### Question:
PlainConsoleLogger implements ConsoleLogger { @Override public void log(Level logLevel, String message) { if (!messageConsumers.containsKey(logLevel)) { return; } Consumer<String> messageConsumer = messageConsumers.get(logLevel); singleThreadedExecutor.execute(() -> messageConsumer.accept(message)); } PlainConsoleLogger(
      ImmutableMap<Level, Consumer<String>> messageConsumers,
      SingleThreadedExecutor singleThreadedExecutor); @Override void log(Level logLevel, String message); @Override void setFooter(List<String> footerLines);  }### Answer:
@Test public void testLog() { ImmutableMap.Builder<Level, Consumer<String>> messageConsumers = ImmutableMap.builder(); for (Level level : Level.values()) { messageConsumers.put(level, createMessageConsumer(level)); } testPlainConsoleLogger = new PlainConsoleLogger(messageConsumers.build(), singleThreadedExecutor); testPlainConsoleLogger.log(Level.LIFECYCLE, "lifecycle"); testPlainConsoleLogger.log(Level.PROGRESS, "progress"); testPlainConsoleLogger.log(Level.INFO, "info"); testPlainConsoleLogger.log(Level.DEBUG, "debug"); testPlainConsoleLogger.log(Level.WARN, "warn"); testPlainConsoleLogger.log(Level.ERROR, "error"); singleThreadedExecutor.shutDownAndAwaitTermination(SHUTDOWN_TIMEOUT); Assert.assertEquals( Arrays.asList( Level.LIFECYCLE, Level.PROGRESS, Level.INFO, Level.DEBUG, Level.WARN, Level.ERROR), levels); Assert.assertEquals( Arrays.asList("lifecycle", "progress", "info", "debug", "warn", "error"), messages); }
@Test public void testLog_ignoreIfNoMessageConsumer() { testPlainConsoleLogger = new PlainConsoleLogger( ImmutableMap.of(Level.WARN, createMessageConsumer(Level.WARN)), singleThreadedExecutor); testPlainConsoleLogger.log(Level.LIFECYCLE, "lifecycle"); testPlainConsoleLogger.log(Level.PROGRESS, "progress"); testPlainConsoleLogger.log(Level.INFO, "info"); testPlainConsoleLogger.log(Level.DEBUG, "debug"); testPlainConsoleLogger.log(Level.WARN, "warn"); testPlainConsoleLogger.log(Level.ERROR, "error"); singleThreadedExecutor.shutDownAndAwaitTermination(SHUTDOWN_TIMEOUT); Assert.assertEquals(Collections.singletonList(Level.WARN), levels); Assert.assertEquals(Collections.singletonList("warn"), messages); }