EofSensorInputStream extends InputStream { @Override public int read() throws IOException { int b = -1; if (isReadAllowed()) { try { b = wrappedStream.read(); checkEOF(b); } catch (final IOException ex) { checkAbort(); throw ex; } } return b; } EofSensorInputStream(final InputStream in,
                                final EofSensorWatcher watcher); @Override int read(); @Override int read(final byte[] b, final int off, final int len); @Override int read(final byte[] b); @Override int available(); @Override void close(); void abort();  }
@Test public void testRead() throws Exception { Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenReturn(Boolean.TRUE); Mockito.when(inStream.read()).thenReturn(0, -1); Assert.assertEquals(0, eofstream.read()); Assert.assertFalse(eofstream.isSelfClosed()); Assert.assertNotNull(eofstream.getWrappedStream()); Mockito.verify(eofwatcher, Mockito.never()).eofDetected(inStream); Assert.assertEquals(-1, eofstream.read()); Assert.assertFalse(eofstream.isSelfClosed()); Assert.assertNull(eofstream.getWrappedStream()); Mockito.verify(inStream, Mockito.times(1)).close(); Mockito.verify(eofwatcher).eofDetected(inStream); Assert.assertEquals(-1, eofstream.read()); }