@Test public void testEOFException() throws Exception { final InputStream input = new TestNullInputStream(2, false, true); assertEquals("Read 1", 0, input.read()); assertEquals("Read 2", 1, input.read()); try { final int result = input.read(); fail("Should have thrown an EOFException, byte=[" + result + "]"); } catch (final EOFException e) { // expected } input.close(); }
@Test public void testSkip() throws Exception { final InputStream input = new TestNullInputStream(10, true, false); assertEquals("Read 1", 0, input.read()); assertEquals("Read 2", 1, input.read()); assertEquals("Skip 1", 5, input.skip(5)); assertEquals("Read 3", 7, input.read()); assertEquals("Skip 2", 2, input.skip(5)); // only 2 left to skip assertEquals("Skip 3 (EOF)", -1, input.skip(5)); // End of file try { input.skip(5); // fail("Expected IOException for skipping after end of file"); } catch (final IOException e) { assertEquals("Skip after EOF IOException message", "Skip after end of file", e.getMessage()); } input.close(); }
@Test public void testMarkNotSupported() throws Exception { final InputStream input = new TestNullInputStream(100, false, true); assertFalse("Mark Should NOT be Supported", input.markSupported()); try { input.mark(5); fail("mark() should throw UnsupportedOperationException"); } catch (final UnsupportedOperationException e) { assertEquals("mark() error message", "Mark not supported", e.getMessage()); } try { input.reset(); fail("reset() should throw UnsupportedOperationException"); } catch (final UnsupportedOperationException e) { assertEquals("reset() error message", "Mark not supported", e.getMessage()); } input.close(); }
int position = 0; final int readlimit = 10; final InputStream input = new TestNullInputStream(100, true, false);
@Test public void testReadByteArray() throws Exception { final byte[] bytes = new byte[10]; final InputStream input = new TestNullInputStream(15);
@Test public void testRead() throws Exception { final int size = 5; final InputStream input = new TestNullInputStream(size); for (int i = 0; i < size; i++) { assertEquals("Check Size [" + i + "]", size - i, input.available()); assertEquals("Check Value [" + i + "]", i, input.read()); } assertEquals("Available after contents all read", 0, input.available()); // Check availbale is zero after End of file assertEquals("End of File", -1, input.read()); assertEquals("Available after End of File", 0, input.available()); // Test reading after the end of file try { final int result = input.read(); fail("Should have thrown an IOException, byte=[" + result + "]"); } catch (final IOException e) { assertEquals("Read after end of file", e.getMessage()); } // Close - should reset input.close(); assertEquals("Available after close", size, input.available()); }