ReleasableOutputStream extends OutputStream { @Override public void close() throws IOException { try { delegate.close(); } finally { safeClose(); isClosed = true; } } ReleasableOutputStream(OutputStream delegate, Runnable onClose); @Override void write(int b); @Override void write(byte[] b); @Override void write(byte[] b, int off, int len); @Override void flush(); @Override void close();  }
@Test public void close() throws Exception { assertFalse(wasCalled.get()); releasableOutputStream.close(); assertTrue(wasCalled.get()); }