UnsyncFilterOutputStream extends OutputStream { @Override public void write(byte[] bytes) throws IOException { write(bytes, 0, bytes.length); } UnsyncFilterOutputStream(OutputStream outputStream); @Override void close(); @Override void flush(); @Override void write(byte[] bytes); @Override void write(byte[] bytes, int offset, int length); @Override void write(int b);  }
@Test public void testWrite() throws IOException { int expectedB = 1; AtomicBoolean writeCalled = new AtomicBoolean(); UnsyncFilterOutputStream unsyncFilterOutputStream = new UnsyncFilterOutputStream( new TestOutputStream() { @Override public void write(int b) { Assert.assertEquals(expectedB, b); writeCalled.set(true); } }); unsyncFilterOutputStream.write(expectedB); Assert.assertTrue(writeCalled.get()); }
@Test public void testWriteBlock() throws IOException { byte[] expectedBytes = new byte[1]; AtomicBoolean writeCalled = new AtomicBoolean(); UnsyncFilterOutputStream unsyncFilterOutputStream = new UnsyncFilterOutputStream( new TestOutputStream() { @Override public void write(byte[] bytes, int offset, int length) { Assert.assertSame(expectedBytes, bytes); Assert.assertEquals(0, offset); Assert.assertEquals(1, length); writeCalled.set(true); } }); unsyncFilterOutputStream.write(expectedBytes); Assert.assertTrue(writeCalled.get()); }