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