DefaultConfigManager implements ConfigManager { @Override public ConfigFile getConfigFile(String namespace, ConfigFileFormat configFileFormat) { String namespaceFileName = String.format("%s.%s", namespace, configFileFormat.getValue()); ConfigFile configFile = m_configFiles.get(namespaceFileName); if (configFile == null) { synchronized (this) { configFile = m_configFiles.get(namespaceFileName); if (configFile == null) { ConfigFactory factory = m_factoryManager.getFactory(namespaceFileName); configFile = factory.createConfigFile(namespaceFileName, configFileFormat); m_configFiles.put(namespaceFileName, configFile); } } } return configFile; } DefaultConfigManager(); @Override Config getConfig(String namespace); @Override ConfigFile getConfigFile(String namespace, ConfigFileFormat configFileFormat);  }
@Test public void testGetConfigFile() throws Exception { String someNamespace = "someName"; ConfigFileFormat someConfigFileFormat = ConfigFileFormat.Properties; ConfigFile configFile = defaultConfigManager.getConfigFile(someNamespace, someConfigFileFormat); assertEquals(someConfigFileFormat, configFile.getConfigFileFormat()); assertEquals(someConfigContent, configFile.getContent()); }
@Test public void testGetConfigFileMultipleTimesWithSameNamespace() throws Exception { String someNamespace = "someName"; ConfigFileFormat someConfigFileFormat = ConfigFileFormat.Properties; ConfigFile someConfigFile = defaultConfigManager.getConfigFile(someNamespace, someConfigFileFormat); ConfigFile anotherConfigFile = defaultConfigManager.getConfigFile(someNamespace, someConfigFileFormat); assertThat( "Get config file multiple times with the same namespace should return the same config file instance", someConfigFile, equalTo(anotherConfigFile)); }