ConsumerCountOutputStream extends OutputStream { @Override public void write(byte[] b, int off, int len) throws IOException { delegate.write(b, off, len); consumer.accept(len); }  @Override void write(byte[] b, int off, int len); @Override void write(int b); @Override void close();  }
@Test public void writeArray() throws IOException { byte[] b = new byte[] { 0, 1, 2 }; int off = 0; int len = 2; underTest.write(b, off, len); verify(delegate).write(b, off, len); verify(consumer).accept(len); }
@Test public void write() throws IOException { underTest.write(0); verify(delegate).write(0); verify(consumer).accept(1); }