UnsyncFilterInputStream extends InputStream { @Override public int read() throws IOException { return inputStream.read(); } UnsyncFilterInputStream(InputStream inputStream); @Override int available(); @Override void close(); @Override void mark(int readLimit); @Override boolean markSupported(); @Override int read(); @Override int read(byte[] bytes); @Override int read(byte[] bytes, int offset, int length); @Override void reset(); @Override long skip(long skip);  }
@Test public void testRead() throws IOException { AtomicBoolean readCalled = new AtomicBoolean(); UnsyncFilterInputStream unsyncFilterInputStream = new UnsyncFilterInputStream( new TestInputStream() { @Override public int read() { readCalled.set(true); return -1; } }); Assert.assertEquals(-1, unsyncFilterInputStream.read()); Assert.assertTrue(readCalled.get()); }
@Test public void testReadBlock() throws IOException { byte[] expectedBytes = new byte[1]; AtomicBoolean readCalled = new AtomicBoolean(); UnsyncFilterInputStream unsyncFilterInputStream = new UnsyncFilterInputStream( new TestInputStream() { @Override public int read(byte[] bytes, int offset, int length) { Assert.assertSame(expectedBytes, bytes); Assert.assertEquals(0, offset); Assert.assertSame(1, length); readCalled.set(true); return -1; } }); Assert.assertEquals(-1, unsyncFilterInputStream.read(expectedBytes)); Assert.assertTrue(readCalled.get()); }