@Test public void shouldWriteEnrichedStackTraceToWriter() throws Exception { StringWriter writer = new StringWriter(); enricher.printStackTrace(exception, writer); assertTrue( "JUnit jar " + JUNIT_JAR_PATTERN + " not found in stack trace written to writer", writer.toString().contains(JUNIT_JAR_PATTERN)); }
@Test public void shouldWriteEnrichedStackTraceToOutputStream() throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); enricher.printStackTrace(exception, outputStream); String output = new String(outputStream.toByteArray()); assertTrue( "JUnit jar " + JUNIT_JAR_PATTERN + " not found in stack trace written to output stream", output.contains(JUNIT_JAR_PATTERN)); }
@Test public void shouldWriteToSystemErrByDefault() { PrintStream originalErrStream = System.err; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); System.setErr(new PrintStream(out)); enricher.printStackTrace(exception); String output = new String(out.toByteArray()); assertTrue( "JUnit jar " + JUNIT_JAR_PATTERN + " not found in stack trace written to default System.err stream", output.contains(JUNIT_JAR_PATTERN)); } finally { System.setErr(originalErrStream); } }