Code example for PipedOutputStream
Methods: close, flush
* Create a PipedOutputStream to get the output from the tested method.
* Pass the PipedOutputStream to the ConsumerPipe's constructor, which
* will create a PipedInputStream in a separate thread.
PipedOutputStream out = new PipedOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(out);
ConsumerPipe cpipe = new ConsumerPipe(out);
* Call the method under test, passing the PipedOutStream to trap the
* The output of the test will be piped to ConsumerPipe's PipedInputStream, which
* is used to read the bytes of the stream into an array. It then creates a
* String for comparison from that byte array.
String result = cpipe.getResult();
//don't forget to close this end of the pipe (ConsumerPipe closes the other end).
assertEquals("Did not get the expected result", expected, result);