SynchronizedWriterDecorator implements ByteArrayWriter { @Override public void flush() throws IOException { synchronized (mutex) { writer.flush(); } } 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 flush() throws IOException { ByteArrayWriter mock = mock(ByteArrayWriter.class); new SynchronizedWriterDecorator(mock, new Object()).flush(); verify(mock).flush(); }