@Test public void testDeprecatedKeys() { Configuration cfg = new Configuration(); cfg.setInteger("the-key", 11); cfg.setInteger("old-key", 12); cfg.setInteger("older-key", 13); ConfigOption<Integer> matchesFirst = ConfigOptions .key("the-key") .defaultValue(-1) .withDeprecatedKeys("old-key", "older-key"); ConfigOption<Integer> matchesSecond = ConfigOptions .key("does-not-exist") .defaultValue(-1) .withDeprecatedKeys("old-key", "older-key"); ConfigOption<Integer> matchesThird = ConfigOptions .key("does-not-exist") .defaultValue(-1) .withDeprecatedKeys("foo", "older-key"); ConfigOption<Integer> notContained = ConfigOptions .key("does-not-exist") .defaultValue(-1) .withDeprecatedKeys("not-there", "also-not-there"); assertEquals(11, cfg.getInteger(matchesFirst)); assertEquals(12, cfg.getInteger(matchesSecond)); assertEquals(13, cfg.getInteger(matchesThird)); assertEquals(-1, cfg.getInteger(notContained)); }
@Test public void testRemove(){ Configuration cfg = new Configuration(); cfg.setInteger("a", 1); cfg.setInteger("b", 2); ConfigOption<Integer> validOption = ConfigOptions .key("a") .defaultValue(-1); ConfigOption<Integer> deprecatedOption = ConfigOptions .key("c") .defaultValue(-1) .withDeprecatedKeys("d", "b"); ConfigOption<Integer> unexistedOption = ConfigOptions .key("e") .defaultValue(-1) .withDeprecatedKeys("f", "g", "j"); assertEquals("Wrong expectation about size", cfg.keySet().size(), 2); assertTrue("Expected 'validOption' is removed", cfg.removeConfig(validOption)); assertEquals("Wrong expectation about size", cfg.keySet().size(), 1); assertTrue("Expected 'existedOption' is removed", cfg.removeConfig(deprecatedOption)); assertEquals("Wrong expectation about size", cfg.keySet().size(), 0); assertFalse("Expected 'unexistedOption' is not removed", cfg.removeConfig(unexistedOption)); } }