### Question:
TeeOutputStream extends ProxyOutputStream { @Override public void close() throws IOException { try { super.close(); } finally { this.branch.close(); } } TeeOutputStream(final OutputStream out, final OutputStream branch); @Override synchronized void write(final byte[] b); @Override synchronized void write(final byte[] b, final int off, final int len); @Override synchronized void write(final int b); @Override void flush(); @Override void close();  }### Answer:
@Test public void testCloseBranchIOException() { final ByteArrayOutputStream badOs = new ExceptionOnCloseByteArrayOutputStream(); final RecordCloseByteArrayOutputStream goodOs = new RecordCloseByteArrayOutputStream(); final TeeOutputStream tos = new TeeOutputStream(goodOs, badOs); try { tos.close(); Assert.fail("Expected " + IOException.class.getName()); } catch (final IOException e) { Assert.assertTrue(goodOs.closed); } }
@Test public void testCloseMainIOException() { final ByteArrayOutputStream badOs = new ExceptionOnCloseByteArrayOutputStream(); final RecordCloseByteArrayOutputStream goodOs = new RecordCloseByteArrayOutputStream(); final TeeOutputStream tos = new TeeOutputStream(badOs, goodOs); try { tos.close(); Assert.fail("Expected " + IOException.class.getName()); } catch (final IOException e) { Assert.assertTrue(goodOs.closed); } }