Use a sorted map to check for deterministic results

This commit is contained in:
games647 2019-05-02 11:44:34 +02:00
parent c59ac3c071
commit 1b493ec94d
No known key found for this signature in database
GPG Key ID: BFC68C8708713A88
2 changed files with 7 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
@ -123,7 +124,10 @@ public class Log4JInstaller {
@VisibleForTesting
protected String mapLoggingLevels(String logFormat, Map<LoggingLevel, String> levelColors) {
String levelFormat = Joiner.on(", ").withKeyValueSeparator('=').join(levelColors);
Map<LoggingLevel, String> sortedColors = new TreeMap<>();
sortedColors.putAll(levelColors);
String levelFormat = Joiner.on(", ").withKeyValueSeparator('=').join(sortedColors);
return logFormat.replace("%level", "%highlight{%level}{" + levelFormat + '}');
}
}

View File

@ -39,7 +39,8 @@ public class Log4JInstallerTest {
levelColors.put(LoggingLevel.TRACE, "blue");
String configFormat = "[%d{HH:mm:ss} %level]: %msg%n";
String expected = "[%d{HH:mm:ss} %highlight{%level}{WARN=yellow, ERROR=red, DEBUG=green, FATAL=red, TRACE=blue, INFO=green}]: %msg%n";
String expected = "[%d{HH:mm:ss} %highlight{%level}{FATAL=red, ERROR=red, WARN=yellow, " +
"INFO=green, DEBUG=green, TRACE=blue}]: %msg%n";
assertThat(installer.mapLoggingLevels(configFormat, levelColors), is(expected));
}