OutputToOutputStreamRedirector extends OutputRedirector { public boolean awaitRunning(long timeout, TimeUnit unit) throws InterruptedException { return running.await(timeout, unit); } OutputToOutputStreamRedirector(OutputStream outputStream);  OutputToOutputStreamRedirector(OutputStream outputStream, int bufferSize); boolean isRunning(); boolean awaitRunning(long timeout, TimeUnit unit); @Override void run(); static final int DEFAULT_PIPE_SIZE; }
@Test public void shouldRedirectOutput() throws Exception { ApplicationConsole console = mock(ApplicationConsole.class); ByteArrayOutputStream out = new ByteArrayOutputStream(1000); PipedOutputStream pipe = new PipedOutputStream(); PipedInputStream in = new PipedInputStream(pipe); OutputToOutputStreamRedirector redirector = new OutputToOutputStreamRedirector(out); redirector.start("foo", "x", in, console, 1234, false); redirector.awaitRunning(1, TimeUnit.MINUTES); pipe.write("Hello ".getBytes()); pipe.write("World!".getBytes()); pipe.flush(); pipe.close(); redirector.join(); assertThat(new String(out.toByteArray()), is("Hello World!")); }