### Question:
ExecPipe { public AsynchronousExecResult exec() throws IOException { PipedInputStream inputStream = null; PipedOutputStream outputStream = null; for (int i = 0; i < builders.size(); i++) { ExecBuilder builder = builders.get(i); if (i != 0) { builder.stdIn(inputStream); } if (i != builders.size() - 1) { outputStream = new PipedOutputStream(); builder.stdOutAndErr(outputStream, null); inputStream = new PipedInputStream(outputStream); } } AsynchronousExecResult lastAsyncResult = null; for (ExecBuilder builder : builders) { lastAsyncResult = builder.asyncExec(); } return lastAsyncResult; } ExecPipe(final ExecBuilder... execBuilders);  ExecPipe(final List<ExecBuilder> execBuilders); AsynchronousExecResult exec(); static ExecPipe pipeOf(final boolean quoteArgs, final String[]... commands); @Override String toString();  }### Answer:
@Test public void testOneStagePipe() throws IOException, InterruptedException { ExecPipe pipe = new ExecPipe( new ExecBuilder("echo").args("test") ); AsynchronousExecResult result = pipe.exec(); result.waitFor(); Assert.assertTrue(result.isSuccessful()); Assert.assertEquals(result.getStdOutResult(), "test\n"); }
@Test public void testSimplePipe() throws IOException, InterruptedException { ExecPipe pipe = new ExecPipe( new ExecBuilder("echo").args("test"), new ExecBuilder("grep").args("te"), new ExecBuilder("wc").args("-l") ); AsynchronousExecResult result = pipe.exec(); result.waitFor(); Assert.assertTrue(result.isSuccessful()); Assert.assertEquals(result.getStdOutResult(), "1\n"); }