ConfigLoader { public SettingsRecord loadMotechSettings() { SettingsRecord settingsRecord; ConfigLocation configLocation = coreConfigurationService.getConfigLocation(); Resource configLocationResource = configLocation.toResource(); try { Resource motechSettings = configLocationResource.createRelative(ConfigurationConstants.SETTINGS_FILE_NAME); settingsRecord = loadSettingsFromStream(motechSettings); settingsRecord.setFilePath(configLocationResource.getURL().getPath()); checkSettingsRecord(settingsRecord); } catch (IOException e) { throw new MotechConfigurationException(String.format("Could not read settings from file at location %s", configLocation), e); } return settingsRecord; }  SettingsRecord loadMotechSettings(); List<File> findExistingConfigs(); SettingsRecord loadDefaultConfig(); @Autowired void setResourceLoader(ResourceLoader resourceLoader); @Autowired void setCoreConfigurationService(CoreConfigurationService coreConfigurationService);  }
@Test public void testMotechSettingsLoading() { final String dirPath = FileHelper.getResourceFile("config/").getAbsolutePath(); ConfigLocation configLocation = new ConfigLocation(dirPath); when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation); MotechSettings settings = configLoader.loadMotechSettings(); assertNotNull(settings); assertEquals(settings.getLanguage(), "en"); }
@Test(expected = MotechConfigurationException.class) public void shouldThrowExceptionIfErrorReadingSettingsFile() throws MalformedURLException { ConfigLocation configLocation = mock(ConfigLocation.class); UrlResource resource = mock(UrlResource.class); when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation); when(configLocation.toResource()).thenReturn(resource); when(resource.createRelative(ConfigurationConstants.SETTINGS_FILE_NAME)).thenThrow(new MalformedURLException()); configLoader.loadMotechSettings(); }