@Override public boolean isOpen() { return wrappedReader.isOpen(); }
@Override public boolean isOpen() { return wrappedReader.isOpen(); }
public static <R> void checkReaderBehavior( DatasetReader<R> reader, int totalRecords, RecordValidator<R> validator) { // this is now used for both initialized and not initialized records because // initialization now happens automatically in newReader if (!reader.isOpen() && reader instanceof InitializeAccessor) { ((InitializeAccessor) reader).initialize(); } try { Assert.assertTrue("Reader should be open", reader.isOpen()); checkReaderIteration(reader, totalRecords, validator); } finally { reader.close(); } Assert.assertFalse("Reader is open after close()", reader.isOpen()); }
} finally { reader.close(); assertFalse("Reader should be closed after calling close", reader.isOpen());
public static <R> void checkReaderIteration(DatasetReader<R> reader, int expectedRecordCount, RecordValidator<R> validator) { int recordCount = 0; Assert.assertTrue("Reader is not open", reader.isOpen()); Assert.assertTrue("Reader has no records, expected " + expectedRecordCount, (expectedRecordCount == 0) || reader.hasNext()); for (R record : reader) { // add calls to hasNext, which should not affect the iteration validator.validate(record, recordCount); Assert.assertNotNull(record); reader.hasNext(); recordCount++; } Assert.assertFalse("Reader is empty, but hasNext is true", reader.hasNext()); // verify that NoSuchElementException is thrown when hasNext returns false try { reader.next(); Assert.fail("Reader did not throw NoSuchElementException"); } catch (NoSuchElementException ex) { // this is the correct behavior } Assert.assertTrue("Reader is empty, but should be open", reader.isOpen()); // verify the correct number of records were produced // if hasNext advances the reader, then this will be wrong Assert.assertEquals("Incorrect number of records", expectedRecordCount, recordCount); }