FAQ - [JAVA] Comment tester un println?

FAQ - [JAVA] Comment tester un println?
En code:
PrintStream out = System.out; try { ByteArrayOutputStream bo = new ByteArrayOutputStream(); System.setOut(new PrintStream(bo)); classUnderTest.fire(); bo.flush(); String allWrittenLines = new String(bo.toByteArray()); assertTrue(allWrittenLines.contains("Running action associated with '1:initial_TO_in progress'")); } catch (Exception e) { e.printStackTrace(); fail("Exception raised"); } finally { System.setOut(out); }