FileReader implements Serializable { public String nextLine() { if (index >= limit) { index = 0; } String line = contents.get(index); index++; return line; } FileReader(String file); String nextLine(); final String file; }
@Test public void testNextLine() { FileReader reader = new FileReader(FILE); assertThat(reader.nextLine()).isEqualTo("first line"); assertThat(reader.nextLine()).isEqualTo("second line"); assertThat(reader.nextLine()).isEqualTo("third line"); assertThat(reader.nextLine()).isEqualTo("first line"); }