@Test public void testDelegationConfigurationWithPrefix() { String prefix = "pref-"; String expectedKey = "key"; /* * Key matches the prefix */ Configuration backingConf = new Configuration(); backingConf.setValueInternal(prefix + expectedKey, "value"); DelegatingConfiguration configuration = new DelegatingConfiguration(backingConf, prefix); Set<String> keySet = configuration.keySet(); assertEquals(keySet.size(), 1); assertEquals(keySet.iterator().next(), expectedKey); /* * Key does not match the prefix */ backingConf = new Configuration(); backingConf.setValueInternal("test-key", "value"); configuration = new DelegatingConfiguration(backingConf, prefix); keySet = configuration.keySet(); assertTrue(keySet.isEmpty()); } }
@Test public void testDelegationConfigurationWithNullPrefix() { Configuration backingConf = new Configuration(); backingConf.setValueInternal("test-key", "value"); DelegatingConfiguration configuration = new DelegatingConfiguration( backingConf, null); Set<String> keySet = configuration.keySet(); assertEquals(keySet, backingConf.keySet()); }