AppConfigServiceImpl implements AppConfigService { @Override public synchronized Map<String, String> loadPreferences() { try { if (preferences == null) { preferences = new HashMap<>(); loadPreferencesFromAllStores(); loadSystemProperties(); setupSystemPropertiesInitializers(); } return preferences; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } } AppConfigServiceImpl(); @Inject  AppConfigServiceImpl(@Any Instance<ApplicationPreferencesLoader> preferencesLoaders,
                                @Any Instance<SystemPropertiesInitializer> systemPropertiesInitializers); void configureOnEvent(@Observes ApplicationStarted applicationStartedEvent); @Override synchronized Map<String, String> loadPreferences(); @Override long getTimestamp();  }
@Test public void systemPropertiesHavePriorityOnPreferencesLoaders() { final Map<String, String> loaderProperties = new HashMap<>(); loaderProperties.put("property1", "loaderProperty1"); loaderProperties.put("property2", "loaderProperty2"); doReturn(loaderProperties).when(preferencesLoader).load(); System.setProperty("property1", "systemProperty1"); System.setProperty("property3", "systemProperty3"); final Map<String, String> preferences = appConfigService.loadPreferences(); assertEquals(2, preferences.size()); assertEquals("systemProperty1", preferences.get("property1")); assertEquals("loaderProperty2", preferences.get("property2")); verify(systemPropertiesInitializer).setSystemProperties(preferences); }