@Test(expected = UnsupportedOperationException.class)
  public void testSetOutputStreamRunning() {
    final InputOutputStreamPump p = new IOSP();
    p.run();

    final OutputStream out = new ClosedOutputStream();
    p.setOutputStream(out);
  }
  @Test
  @SuppressWarnings("unchecked")
  public void testPumpBothClosed() {
    final InputStream in = new ClosedInputStream();
    final OutputStream out = new ClosedOutputStream();

    final EventListener<IOException> el = context.mock(EventListener.class);
    context.checking(
        new Expectations() {
          {
            never(el).receive(with(any(Object.class)), with(any(IOException.class)));
          }
        });

    final InputOutputStreamPump p = new InputOutputStreamPump(in, out, el);
    p.run();
  }
  @Test
  @SuppressWarnings("unchecked")
  public void testPumpOutClosed() {
    final byte[] eout = "Jackdaws love my big sphinx of quartz.\n".getBytes();

    final ByteArrayInputStream in = new ByteArrayInputStream(eout);
    final OutputStream out = new ClosedOutputStream();

    final EventListener<IOException> el = context.mock(EventListener.class);
    context.checking(
        new Expectations() {
          {
            oneOf(el)
                .receive(with(aNonNull(InputOutputStreamPump.class)), with(any(IOException.class)));
          }
        });

    final InputOutputStreamPump p = new InputOutputStreamPump(in, out, el);
    p.run();
  }
  @Test
  @SuppressWarnings("unchecked")
  public void testPumpNormal() {
    final byte[] eout = "Jackdaws love my big sphinx of quartz.\n".getBytes();

    final ByteArrayInputStream in = new ByteArrayInputStream(eout);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();

    final EventListener<IOException> el = context.mock(EventListener.class);
    context.checking(
        new Expectations() {
          {
            never(el).receive(with(any(Object.class)), with(any(IOException.class)));
          }
        });

    final InputOutputStreamPump p = new InputOutputStreamPump(in, out, el);
    p.run();

    assertArrayEquals(eout, out.toByteArray());
  }