### Question:
NoClosePipedOutputStream extends OutputStream { public synchronized void connect(NoClosePipedInputStream snk) throws IOException { if (snk == null) { throw new NullPointerException(); } else if (sink != null) { throw new IOException("Already connected"); } sink = snk; snk.in = -1; snk.out = 0; snk.connected = true; } NoClosePipedOutputStream(NoClosePipedInputStream snk);  NoClosePipedOutputStream(); synchronized void connect(NoClosePipedInputStream snk); void write(int b); void write(byte b[], int off, int len);  }### Answer:
@Test public void testConnectToNullSource() { try { out.connect(null); fail("This test should have already thrown a NullPointerException"); } catch (NullPointerException e) { return; } catch (IOException e) { fail("The pipe is already connected"); } fail("This test should have caught a NullPointerException"); }
@Test public void testConnectWhenAlreadyConnected () { try { out.connect(in); out.connect(in); fail("This test should have thrown an IOException already"); } catch (IOException e) { assertEquals("Already connected", e.getMessage()); return; } catch (NullPointerException e) { fail ("The source being connected to is null"); } fail("This test should have caught an IOException"); }
@Test public void testNormalConnect() { try { out.connect(in); } catch (IOException e) { fail("The pipe is already connected"); } catch(NullPointerException e) { fail("The source being connected to is null"); } }