ErrorFilteredConsumer implements LineConsumer { @Override public void writeLine(String line) throws IOException { if (errorIndicator.isError(line)) { lineConsumer.writeLine(line); } } ErrorFilteredConsumer(ErrorIndicator errorIndicator, LineConsumer lineConsumer);  ErrorFilteredConsumer(LineConsumer lineConsumer); @Override void writeLine(String line); @Override void close();  }
@Test public void testRedirect() throws Exception { LineConsumer lineConsumer = mock(LineConsumer.class); ErrorFilteredConsumer errorFilteredConsumer = new ErrorFilteredConsumer(lineConsumer); errorFilteredConsumer.writeLine("Line 1"); errorFilteredConsumer.writeLine("Line 2"); errorFilteredConsumer.writeLine("[STDERR] Line 3"); errorFilteredConsumer.writeLine("[STDERR] Line 4"); errorFilteredConsumer.writeLine("Line 5"); verify(lineConsumer).writeLine("[STDERR] Line 3"); verify(lineConsumer).writeLine("[STDERR] Line 4"); }