Repository: GoogleContainerTools/jib
File: jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/logging/PlainConsoleLoggerTest.java (Java)

Code before:
import org.junit.Test;

/** Tests for {@link PlainConsoleLogger}. */
public class PlainConsoleLoggerTest {

  private static final Duration SHUTDOWN_TIMEOUT = Duration.ofSeconds(3);

  private final SingleThreadedExecutor singleThreadedExecutor = new SingleThreadedExecutor();

  private final List<Level> levels = new ArrayList<>();
  private final List<String> messages = new ArrayList<>();

  private PlainConsoleLogger testPlainConsoleLogger;

  @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, "\u001B[36;1mlifecycle\u001B[0m");
    testPlainConsoleLogger.log(Level.PROGRESS, "\u001B[33m progress\u001B[0m");
    testPlainConsoleLogger.log(Level.INFO, "info");
    testPlainConsoleLogger.log(Level.DEBUG, "debug");
    testPlainConsoleLogger.log(Level.WARN, "warn");
    testPlainConsoleLogger.log(Level.ERROR, "\u001B[31;1m error \u001B[0m");

    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");

Review comment (suggestion):
perhaps we can remove the spaces here and below: 
```suggestion
    testPlainConsoleLogger.log(Level.PROGRESS, "\u001B[33mprogress\u001B[0m");
```

Code after:
import org.junit.Test;

/** Tests for {@link PlainConsoleLogger}. */
public class PlainConsoleLoggerTest {

  private static final Duration SHUTDOWN_TIMEOUT = Duration.ofSeconds(3);

  private final SingleThreadedExecutor singleThreadedExecutor = new SingleThreadedExecutor();

  private final List<Level> levels = new ArrayList<>();
  private final List<String> messages = new ArrayList<>();

  private PlainConsoleLogger testPlainConsoleLogger;

  @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_filterOutColors() {
    ImmutableMap.Builder<Level, Consumer<String>> messageConsumers = ImmutableMap.builder();
    for (Level level : Level.values()) {
      messageConsumers.put(level, createMessageConsumer(level));
    }

    testPlainConsoleLogger =
        new PlainConsoleLogger(messageConsumers.build(), singleThreadedExecutor);