InternalLogger { public static void log(final Level level, final String message) { System.err.println("LOGGER " + level + ": " + message); } private  InternalLogger(); static void log(final Level level, final String message); static void log(final Level level, final Throwable exception); static void log(final Level level, final Throwable exception, final String message);  }
@Test public void textMessage() { InternalLogger.log(severityLevel, "Hello World!"); assertThat(systemStream.consumeErrorOutput()) .startsWith("LOGGER ") .containsOnlyOnce(outputLevel) .containsOnlyOnce("Hello World!") .endsWith(System.lineSeparator()) .hasLineCount(1); }
@Test public void exception() { InternalLogger.log(severityLevel, new NullPointerException()); assertThat(systemStream.consumeErrorOutput()) .startsWith("LOGGER ") .containsOnlyOnce(outputLevel) .containsOnlyOnce(NullPointerException.class.getName()) .endsWith(System.lineSeparator()) .hasLineCount(1); }
@Test public void exceptionWithDescription() { InternalLogger.log(severityLevel, new IOException("File not found")); assertThat(systemStream.consumeErrorOutput()) .startsWith("LOGGER ") .containsOnlyOnce(outputLevel) .containsOnlyOnce(IOException.class.getName()) .containsOnlyOnce("File not found") .endsWith(System.lineSeparator()) .hasLineCount(1); }
@Test public void exceptionAndTextMessage() { InternalLogger.log(severityLevel, new NullPointerException(), "Hello World!"); assertThat(systemStream.consumeErrorOutput()) .startsWith("LOGGER ") .containsOnlyOnce(outputLevel) .containsOnlyOnce(NullPointerException.class.getName()) .containsOnlyOnce("Hello World!") .endsWith(System.lineSeparator()) .hasLineCount(1); }
@Test public void exceptionWithDescriptionAndTextMessage() { InternalLogger.log(severityLevel, new IOException("File not found"), "Hello World!"); assertThat(systemStream.consumeErrorOutput()) .startsWith("LOGGER ") .containsOnlyOnce(outputLevel) .containsOnlyOnce(IOException.class.getName()) .containsOnlyOnce("File not found") .containsOnlyOnce("Hello World!") .endsWith(System.lineSeparator()) .hasLineCount(1); }