ConfigurationParser { public static Map<String, Level> getCustomLevels() { Map<String, Level> levels = new HashMap<String, Level>(); for (Entry<String, String> entry : Configuration.getSiblings("level@").entrySet()) { String packageOrClass = entry.getKey().substring("level@".length()); Level level = parse(entry.getValue(), null); if (level != null) { levels.put(packageOrClass, level); } } return levels; } private  ConfigurationParser(); static Level getGlobalLevel(); static Map<String, Level> getCustomLevels(); static List<String> getTags(); static boolean isWritingThreadEnabled(); static boolean isAutoShutdownEnabled(); static Level parse(final String property, final Level defaultValue);  }
@Test public void noCustomLevels() { Map<String, Level> levels = ConfigurationParser.getCustomLevels(); assertThat(levels).isEmpty(); }
@Test public void singleCustomLevel() { Configuration.set("level@com.test", "info"); Map<String, Level> levels = ConfigurationParser.getCustomLevels(); assertThat(levels).containsOnly(entry("com.test", Level.INFO)); }
@Test public void multipleCustomLevels() { Configuration.set("level@test", "debug"); Configuration.set("level@test.a", "info"); Configuration.set("level@test.b", "warn"); Configuration.set("level@other", "error"); Map<String, Level> levels = ConfigurationParser.getCustomLevels(); assertThat(levels).containsOnly( entry("test", Level.DEBUG), entry("test.a", Level.INFO), entry("test.b", Level.WARN), entry("other", Level.ERROR)); }
@Test public void illegalCustomLevel() { Configuration.set("level@test", "42"); Configuration.set("level@other", "info"); Map<String, Level> levels = ConfigurationParser.getCustomLevels(); assertThat(levels).containsOnly(entry("other", Level.INFO)); assertThat(systemStream.consumeErrorOutput()).containsOnlyOnce("ERROR").containsOnlyOnce("severity level").containsOnlyOnce("42"); }