Add more debug log flavors to ConsoleLogger
This commit is contained in:
@@ -19,8 +19,10 @@ import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
@@ -42,9 +44,6 @@ public class ConsoleLoggerTest {
|
||||
@Mock
|
||||
private Logger logger;
|
||||
|
||||
@Mock
|
||||
private Settings settings;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@@ -106,7 +105,7 @@ public class ConsoleLoggerTest {
|
||||
ConsoleLogger.warning("Encountered a warning");
|
||||
|
||||
// then
|
||||
verify(logger).info("Debug: Created test");
|
||||
verify(logger).info("[DEBUG] Created test");
|
||||
verify(logger).warning("Encountered a warning");
|
||||
verifyNoMoreInteractions(logger);
|
||||
assertThat(logFile.length(), equalTo(0L));
|
||||
@@ -137,6 +136,35 @@ public class ConsoleLoggerTest {
|
||||
assertThat(String.join("", loggedLines), containsString(getClass().getCanonicalName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSupportVariousDebugMethods() throws IOException {
|
||||
// given
|
||||
ConsoleLogger.setLoggingOptions(newSettings(true, LogLevel.DEBUG));
|
||||
|
||||
// when
|
||||
ConsoleLogger.debug("Got {0} entries", "test");
|
||||
ConsoleLogger.debug("Player `{0}` is in world `{1}`", "Bobby", "world");
|
||||
ConsoleLogger.debug("The {0} is {1} the {2}", "fox", "behind", "chicken");
|
||||
ConsoleLogger.debug("{0} quick {1} jump over {2} lazy {3} (reason: {4})", 5, "foxes", 3, "dogs", null);
|
||||
ConsoleLogger.debug(() -> "Too little too late");
|
||||
|
||||
// then
|
||||
verify(logger).log(Level.INFO, "[DEBUG] Got {0} entries", "test");
|
||||
verify(logger).log(Level.INFO, "[DEBUG] Player `{0}` is in world `{1}`", new Object[]{"Bobby", "world"});
|
||||
verify(logger).log(Level.INFO, "[DEBUG] The {0} is {1} the {2}", new Object[]{"fox", "behind", "chicken"});
|
||||
verify(logger).log(Level.INFO, "[DEBUG] {0} quick {1} jump over {2} lazy {3} (reason: {4})",
|
||||
new Object[]{"5", "foxes", "3", "dogs", "null"});
|
||||
verify(logger).info("[DEBUG] Too little too late");
|
||||
|
||||
List<String> loggedLines = Files.readAllLines(logFile.toPath(), StandardCharsets.UTF_8);
|
||||
assertThat(loggedLines, contains(
|
||||
containsString("[DEBUG] Got {0} entries {test}"),
|
||||
containsString("[DEBUG] Player `{0}` is in world `{1}` {Bobby, world}"),
|
||||
containsString("[DEBUG] The {0} is {1} the {2} {fox, behind, chicken}"),
|
||||
containsString("[DEBUG] {0} quick {1} jump over {2} lazy {3} (reason: {4}) {5, foxes, 3, dogs, null}"),
|
||||
containsString("[DEBUG] Too little too late")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveHiddenConstructor() {
|
||||
TestHelper.validateHasOnlyPrivateEmptyConstructor(ConsoleLogger.class);
|
||||
|
||||
Reference in New Issue
Block a user