LogHandler { public void log(final Report report) { logErrorMessages(report); logInfoMessages(report); } LogHandler(final TaskListener listener, final String name);  LogHandler(final TaskListener listener, final String name, final Report report); private  LogHandler(final TaskListener listener, final String name, final int infoPosition,
            final int errorPosition); void log(final Report report); @FormatMethod void log(final String format, final Object... args);  }
@Test void shouldLogInfoAndErrorMessage() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(outputStream); TaskListener taskListener = createTaskListener(printStream); Report report = new Report(); report.logInfo(NOT_SHOWN); report.logError(NOT_SHOWN); LogHandler logHandler = new LogHandler(taskListener, LOG_HANDLER_NAME, report); report.logInfo(MESSAGE); report.logError(MESSAGE); logHandler.log(report); assertThat(outputStream.toString()).isEqualTo(String.format( "[%s] [-ERROR-] %s%n" + "[%s] %s%n", LOG_HANDLER_NAME, MESSAGE, LOG_HANDLER_NAME, MESSAGE)); report.logInfo(ADDITIONAL_MESSAGE); report.logError(ADDITIONAL_MESSAGE); logHandler.log(report); assertThat(outputStream.toString()).isEqualTo(String.format( "[%s] [-ERROR-] %s%n" + "[%s] %s%n" + "[%s] [-ERROR-] %s%n" + "[%s] %s%n", LOG_HANDLER_NAME, MESSAGE, LOG_HANDLER_NAME, MESSAGE, LOG_HANDLER_NAME, ADDITIONAL_MESSAGE, LOG_HANDLER_NAME, ADDITIONAL_MESSAGE)); }
@Test void shouldLogFormattedMessage() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(outputStream); TaskListener taskListener = createTaskListener(printStream); LogHandler logHandler = new LogHandler(taskListener, LOG_HANDLER_NAME); logHandler.log(LOGGER_MESSAGE); assertThat(outputStream.toString()) .isEqualTo(String.format("[%s] %s%n", LOG_HANDLER_NAME, LOGGER_MESSAGE)); }