@Test(expected = MotechConfigurationException.class) public void shouldThrowExceptionIfNoneOfTheFilesInTheDefaultLocationIsReadable() { List<ConfigLocation> configLocationList = new ArrayList<>(); ConfigLocation configLocationMock = Mockito.mock(ConfigLocation.class); configLocationList.add(configLocationMock); when(configLocationMock.getLocation()).thenReturn("location"); when(configLocationMock.getFile("fileName", ConfigLocation.FileAccessType.READABLE)).thenThrow( new MotechConfigurationException("File is not readable")); when(configLocationMock.getLocation()).thenReturn("location"); ConfigPropertiesUtils.getDefaultPropertiesFile(ConfigLocation.FileAccessType.READABLE, configLocationList, "fileName"); }
public static File getDefaultPropertiesFile(ConfigLocation.FileAccessType accessType, Iterable<ConfigLocation> configLocations, String fileName) { StringBuilder sb = new StringBuilder(""); for (ConfigLocation configLocation : configLocations) { sb.append(configLocation.getLocation()).append(' '); try { return configLocation.getFile(fileName, accessType); } catch (MotechConfigurationException e) { LOGGER.warn(e.getMessage()); } } throw new MotechConfigurationException(String.format("%s file is not %s from any of the default locations. Searched directories: %s.", fileName, accessType.toString(), sb)); }
ConfigPropertiesUtils { public static File getDefaultPropertiesFile(ConfigLocation.FileAccessType accessType, Iterable<ConfigLocation> configLocations, String fileName) { StringBuilder sb = new StringBuilder(""); for (ConfigLocation configLocation : configLocations) { sb.append(configLocation.getLocation()).append(' '); try { return configLocation.getFile(fileName, accessType); } catch (MotechConfigurationException e) { LOGGER.warn(e.getMessage()); } } throw new MotechConfigurationException(String.format("%s file is not %s from any of the default locations. Searched directories: %s.", fileName, accessType.toString(), sb)); } }
ConfigPropertiesUtils { public static File getDefaultPropertiesFile(ConfigLocation.FileAccessType accessType, Iterable<ConfigLocation> configLocations, String fileName) { StringBuilder sb = new StringBuilder(""); for (ConfigLocation configLocation : configLocations) { sb.append(configLocation.getLocation()).append(' '); try { return configLocation.getFile(fileName, accessType); } catch (MotechConfigurationException e) { LOGGER.warn(e.getMessage()); } } throw new MotechConfigurationException(String.format("%s file is not %s from any of the default locations. Searched directories: %s.", fileName, accessType.toString(), sb)); } private  ConfigPropertiesUtils(); }
ConfigPropertiesUtils { public static File getDefaultPropertiesFile(ConfigLocation.FileAccessType accessType, Iterable<ConfigLocation> configLocations, String fileName) { StringBuilder sb = new StringBuilder(""); for (ConfigLocation configLocation : configLocations) { sb.append(configLocation.getLocation()).append(' '); try { return configLocation.getFile(fileName, accessType); } catch (MotechConfigurationException e) { LOGGER.warn(e.getMessage()); } } throw new MotechConfigurationException(String.format("%s file is not %s from any of the default locations. Searched directories: %s.", fileName, accessType.toString(), sb)); } private  ConfigPropertiesUtils(); static Properties getPropertiesFromFile(File file); static void saveConfig(File file, Properties properties); static File getDefaultPropertiesFile(ConfigLocation.FileAccessType accessType, Iterable<ConfigLocation> configLocations,
                                                String fileName); static Properties getPropertiesFromSystemVarString(String string); static PropertiesConfiguration createPropertiesConfiguration(String basePath, String fileName); }
ConfigPropertiesUtils { public static File getDefaultPropertiesFile(ConfigLocation.FileAccessType accessType, Iterable<ConfigLocation> configLocations, String fileName) { StringBuilder sb = new StringBuilder(""); for (ConfigLocation configLocation : configLocations) { sb.append(configLocation.getLocation()).append(' '); try { return configLocation.getFile(fileName, accessType); } catch (MotechConfigurationException e) { LOGGER.warn(e.getMessage()); } } throw new MotechConfigurationException(String.format("%s file is not %s from any of the default locations. Searched directories: %s.", fileName, accessType.toString(), sb)); } private  ConfigPropertiesUtils(); static Properties getPropertiesFromFile(File file); static void saveConfig(File file, Properties properties); static File getDefaultPropertiesFile(ConfigLocation.FileAccessType accessType, Iterable<ConfigLocation> configLocations,
                                                String fileName); static Properties getPropertiesFromSystemVarString(String string); static PropertiesConfiguration createPropertiesConfiguration(String basePath, String fileName);  }