TrackingOutputStream extends OutputStream { public void write( final int b ) throws IOException { wrappedStream.write( b ); trackingSize++; } TrackingOutputStream( final OutputStream wrapped ); void write( final int b ); void write( final byte[] b ); void write( final byte[] b, final int off, final int len ); void flush(); void close(); OutputStream getWrappedStream(); int getTrackingSize();  }
@Test public void testWrite() throws Exception { streamSpy.write( 1 ); verify( streamSpy, times( 1 ) ).write( anyInt() ); assertEquals( 1, streamSpy.getTrackingSize() ); streamSpy.write( new byte[] { 1 } ); verify( streamSpy, times( 1 ) ).write( any( byte[].class ) ); assertEquals( 2, streamSpy.getTrackingSize() ); streamSpy.write( new byte[] { 1 }, 0, 3 ); verify( streamSpy, times( 1 ) ).write( any( byte[].class ), anyInt(), anyInt() ); assertEquals( 5, streamSpy.getTrackingSize() ); }