SynchronizedWriterDecorator implements ByteArrayWriter { @Override public void write(final byte[] data, final int length) throws IOException { synchronized (mutex) { writer.write(data, length); } } SynchronizedWriterDecorator(final ByteArrayWriter writer, final Object mutex); @Override void write(final byte[] data, final int length); @Override void flush(); @Override void close();  }
@Test public void write() throws IOException { ByteArrayWriter mock = mock(ByteArrayWriter.class); byte[] data = new byte[0]; new SynchronizedWriterDecorator(mock, new Object()).write(data, 42); verify(mock).write(data, 42); }