@Test public void testLoadPropertiesException() { String configPath = System.getProperty("user.dir") + "/src/test/resources/does/not/exist.properties"; try { Config properties = PropertiesFileReader.loadPropertiesFile(configPath); fail("Exception should be thrown because the test file shouldn't exist"); } catch (Exception e) { assertEquals(EtiqetException.class, e.getClass()); assertTrue(e.getMessage().startsWith("java.io.FileNotFoundException")); } }
public static Config loadPropertiesFile(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); try (FileReader reader = new FileReader(fileName)) { Properties p = new Properties(); p.load(reader); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } Config config = new Config(); config.setProperties(propertyMap); return config; } catch (Exception e) { throw new EtiqetException(e); } }
PropertiesFileReader { public static Config loadPropertiesFile(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); try (FileReader reader = new FileReader(fileName)) { Properties p = new Properties(); p.load(reader); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } Config config = new Config(); config.setProperties(propertyMap); return config; } catch (Exception e) { throw new EtiqetException(e); } } }
PropertiesFileReader { public static Config loadPropertiesFile(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); try (FileReader reader = new FileReader(fileName)) { Properties p = new Properties(); p.load(reader); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } Config config = new Config(); config.setProperties(propertyMap); return config; } catch (Exception e) { throw new EtiqetException(e); } } private  PropertiesFileReader(); }
PropertiesFileReader { public static Config loadPropertiesFile(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); try (FileReader reader = new FileReader(fileName)) { Properties p = new Properties(); p.load(reader); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } Config config = new Config(); config.setProperties(propertyMap); return config; } catch (Exception e) { throw new EtiqetException(e); } } private  PropertiesFileReader(); static Config loadPropertiesFile(String fileName); static Map<String, String> loadFromClasspath(String fileName); }
PropertiesFileReader { public static Config loadPropertiesFile(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); try (FileReader reader = new FileReader(fileName)) { Properties p = new Properties(); p.load(reader); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } Config config = new Config(); config.setProperties(propertyMap); return config; } catch (Exception e) { throw new EtiqetException(e); } } private  PropertiesFileReader(); static Config loadPropertiesFile(String fileName); static Map<String, String> loadFromClasspath(String fileName);  }