StringRecordReader implements RecordReader<String> { @Override public StringRecord readRecord() { Header header = new Header(currentRecordNumber++, getDataSourceName(), LocalDateTime.now()); String payload = scanner.hasNextLine() ? scanner.nextLine() : null; return payload == null ? null : new StringRecord(header, payload); } StringRecordReader(final String dataSource); @Override void open(); @Override StringRecord readRecord(); @Override void close();  }
@Test public void whenTheDataSourceIsNotEmpty_ThenThereShouldBeANextRecordToRead() { assertThat(stringRecordReader.readRecord()).isNotNull(); }
@Test public void whenTheDataSourceIsEmpty_ThenThereShouldBeNoNextRecordToRead() { setupEmptyDataSource(); assertThat(stringRecordReader.readRecord()).isNull(); }
@Test public void whenTheDataSourceIsNotEmpty_ThenTheNextRecordShouldBeReadCorrectly() { Record record = stringRecordReader.readRecord(); assertThat(record).isInstanceOf(StringRecord.class); assertThat(record.getHeader()).isNotNull(); assertThat(record.getHeader().getNumber()).isEqualTo(1L); assertThat(record.getPayload()).isEqualTo("foo"); record = stringRecordReader.readRecord(); assertThat(record).isInstanceOf(StringRecord.class); assertThat(record.getHeader()).isNotNull(); assertThat(record.getHeader().getNumber()).isEqualTo(2L); assertThat(record.getPayload()).isEqualTo("bar"); assertThat(stringRecordReader.readRecord()).isNull(); }