ByteArrayOutputStream stringErr = new ByteArrayOutputStream();
System.setOut(new PrintStream(stringOut));
System.setErr(new PrintStream(stringErr));
try {
// check that nothing is written to stdout or stderr while hidden
HideOutput ho = new HideOutput();
System.out.print(message);
System.err.print(message);
Assert.assertEquals("", stringOut.toString());
Assert.assertEquals("", stringErr.toString());
// check that data is again written to stdout and stderr after restoring
ho.restoreOutput();
System.out.print(message);
System.err.print(message);
Assert.assertEquals(message, stringOut.toString());
Assert.assertEquals(message, stringErr.toString());
}