mirror of
https://github.com/games647/ColorConsole.git
synced 2024-11-27 04:46:01 +01:00
Use a sorted map to check for deterministic results
This commit is contained in:
parent
c59ac3c071
commit
1b493ec94d
@ -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 + '}');
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user