PropertiesCompatibleFileConfigRepository extends AbstractConfigRepository implements
    ConfigFileChangeListener { @Override public Properties getConfig() { if (cachedProperties == null) { sync(); } return cachedProperties; } PropertiesCompatibleFileConfigRepository(PropertiesCompatibleConfigFile configFile); @Override Properties getConfig(); @Override void setUpstreamRepository(ConfigRepository upstreamConfigRepository); @Override ConfigSourceType getSourceType(); @Override void onChange(ConfigFileChangeEvent changeEvent);  }
@Test public void testGetConfig() throws Exception { PropertiesCompatibleFileConfigRepository configFileRepository = new PropertiesCompatibleFileConfigRepository( configFile); assertSame(someProperties, configFileRepository.getConfig()); verify(configFile, times(1)).addChangeListener(configFileRepository); }
@Test public void testGetConfigFailedAndThenRecovered() throws Exception { RuntimeException someException = new RuntimeException("some exception"); when(configFile.asProperties()).thenThrow(someException); PropertiesCompatibleFileConfigRepository configFileRepository = new PropertiesCompatibleFileConfigRepository( configFile); Throwable exceptionThrown = null; try { configFileRepository.getConfig(); } catch (Throwable ex) { exceptionThrown = ex; } assertSame(someException, exceptionThrown); reset(configFile); Properties someProperties = mock(Properties.class); when(configFile.asProperties()).thenReturn(someProperties); assertSame(someProperties, configFileRepository.getConfig()); }
@Test(expected = IllegalStateException.class) public void testGetConfigWithConfigFileReturnNullProperties() throws Exception { when(configFile.asProperties()).thenReturn(null); PropertiesCompatibleFileConfigRepository configFileRepository = new PropertiesCompatibleFileConfigRepository( configFile); configFileRepository.getConfig(); }