Improve coverage of LogHandler.
@@ -6,6 +6,7 @@ import java.io.PrintStream;
import org.junit.jupiter.api.Test;
import edu.hm.hafner.analysis.Report;
+import edu.hm.hafner.util.FilteredLog;
import hudson.model.TaskListener;
@@ -24,6 +25,20 @@ class LogHandlerTest {
private static final String ADDITIONAL_MESSAGE = "Additional";
private static final String LOGGER_MESSAGE = "Logger message";
+ @Test
+ void shouldLogNothing() {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ PrintStream printStream = new PrintStream(outputStream);
+ TaskListener taskListener = createTaskListener(printStream);
+
+ Report report = new Report();
+
+ LogHandler logHandler = new LogHandler(taskListener, LOG_HANDLER_NAME, report);
+ logHandler.log(report);
+
+ assertThat(outputStream.toString()).isEmpty();
+ }
+
@Test
void shouldLogInfoAndErrorMessage() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@@ -71,6 +86,22 @@ class LogHandlerTest {
.isEqualTo(String.format("[%s] %s%n", LOG_HANDLER_NAME, LOGGER_MESSAGE));
}
+ @Test
+ void shouldLogFormattedLogger() {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ PrintStream printStream = new PrintStream(outputStream);
+ TaskListener taskListener = createTaskListener(printStream);
+ LogHandler logHandler = new LogHandler(taskListener, LOG_HANDLER_NAME);
+
+ FilteredLog filteredLog = new FilteredLog("Error");
+ filteredLog.logInfo(LOGGER_MESSAGE);
+
+ logHandler.log(filteredLog);
+
+ assertThat(outputStream.toString())
+ .isEqualTo(String.format("[%s] %s%n", LOG_HANDLER_NAME, LOGGER_MESSAGE));
+ }
+
private TaskListener createTaskListener(final PrintStream printStream) {
TaskListener taskListener = mock(TaskListener.class);
when(taskListener.getLogger()).thenReturn(printStream);
