### Question:
PropertiesFileLoader implements ConfigurationLoader { @Override public Properties loadConfigurations() { Properties properties = new Properties(); InputStream inputStream = null; try { if (propertiesFilePath.startsWith("classpath:")) { String realPropertiesFilePath = propertiesFilePath.split("classpath:")[1]; inputStream = PropertiesFileLoader.class.getResourceAsStream(realPropertiesFilePath); if(inputStream == null) { throw new FileNotFoundException(realPropertiesFilePath + " (No such file or directory)"); } } else { File file = Paths.get(propertiesFilePath).toFile(); inputStream = new FileInputStream(file); } properties.load(inputStream); } catch (IOException e) { throw new RuntimeException("Error while loading properties cause: ", e); } finally { if(inputStream != null) { try { inputStream.close(); } catch (IOException e) { LOGGER.warning("Error while closing inputStream cause: " + e); } } } return properties; } PropertiesFileLoader(String propertiesFilePath); @Override Properties loadConfigurations();  }### Answer:
@Test public void loadConfigurationsFromFS() throws IOException { Path path = null; try { path = Files.createTempFile("file-load", "unit-test"); InputStream propertiesInputStream = PropertiesFileLoaderTest.class.getResourceAsStream("/test.properties"); Files.copy(propertiesInputStream, path, StandardCopyOption.REPLACE_EXISTING); PropertiesFileLoader propertiesFileLoader = new PropertiesFileLoader(path.toAbsolutePath().toString()); Properties properties = propertiesFileLoader.loadConfigurations(); assertNotNull(properties); assertEquals(properties.getProperty("thisIsATestProperty"), "someTest"); } finally { if (path != null) { Files.delete(path); } } }
@Test public void loadConfigurationsFromClasspath() throws IOException { PropertiesFileLoader propertiesFileLoader = new PropertiesFileLoader("classpath:/test.properties"); Properties properties = propertiesFileLoader.loadConfigurations(); assertNotNull(properties); assertEquals(properties.getProperty("thisIsATestProperty"), "someTest"); }
@Test(expected = RuntimeException.class) public void loadConfigurationsFromFSNotFound() { PropertiesFileLoader propertiesFileLoader = new PropertiesFileLoader("/this/file/do/not/exists/######"); propertiesFileLoader.loadConfigurations(); fail(); }
@Test(expected = RuntimeException.class) public void loadConfigurationsFromClasspathNotFound() { PropertiesFileLoader propertiesFileLoader = new PropertiesFileLoader("classpath:/this/file/do/not/exists/######"); propertiesFileLoader.loadConfigurations(); fail(); }