DefaultConfigManager implements ConfigManager { @Override public Config getConfig(String namespace) { Config config = m_configs.get(namespace); if (config == null) { synchronized (this) { config = m_configs.get(namespace); if (config == null) { ConfigFactory factory = m_factoryManager.getFactory(namespace); config = factory.create(namespace); m_configs.put(namespace, config); } } } return config; } DefaultConfigManager(); @Override Config getConfig(String namespace); @Override ConfigFile getConfigFile(String namespace, ConfigFileFormat configFileFormat);  }
@Test public void testGetConfig() throws Exception { String someNamespace = "someName"; String anotherNamespace = "anotherName"; String someKey = "someKey"; Config config = defaultConfigManager.getConfig(someNamespace); Config anotherConfig = defaultConfigManager.getConfig(anotherNamespace); assertEquals(someNamespace + ":" + someKey, config.getProperty(someKey, null)); assertEquals(anotherNamespace + ":" + someKey, anotherConfig.getProperty(someKey, null)); }
@Test public void testGetConfigMultipleTimesWithSameNamespace() throws Exception { String someNamespace = "someName"; Config config = defaultConfigManager.getConfig(someNamespace); Config anotherConfig = defaultConfigManager.getConfig(someNamespace); assertThat( "Get config multiple times with the same namespace should return the same config instance", config, equalTo(anotherConfig)); }