@Test public void testStdoutCaptureDetail() { ThreadLocalPrintStream.stdout(); System.out.println("1 - not captured, but next goes to capture only"); OutputCapturingContext capture = ThreadLocalPrintStream.stdout().capture(); final String TWO = "2 - captured"; System.out.println(TWO); Assert.assertEquals(TWO, capture.getOutputSoFar().trim()); String out = capture.end(); Assert.assertEquals(TWO, out.trim()); System.out.println("3 - not captured, restored normal output"); Assert.assertEquals(TWO, capture.getOutputSoFar().trim()); }
@Test public void testStderrCaptureDetail() { ThreadLocalPrintStream.stderr(); System.err.println("1 - not captured, but next goes to capture only"); OutputCapturingContext capture = ThreadLocalPrintStream.stderr().capture(); final String TWO = "2 - captured"; System.err.println(TWO); Assert.assertEquals(TWO, capture.getOutputSoFar().trim()); String out = capture.end(); Assert.assertEquals(TWO, out.trim()); System.err.println("3 - not captured, restored normal output"); Assert.assertEquals(TWO, capture.getOutputSoFar().trim()); }