@Test public void testLoadFromClasspathException() { String configPath = "/properties/does/not/exist.properties"; try { Map<String, String> properties = PropertiesFileReader.loadFromClasspath(configPath); fail("Exception should be thrown because the test file shouldn't exist"); } catch (Exception e) { assertEquals(EtiqetException.class, e.getClass()); assertEquals("Could not read classpath file " + configPath, e.getMessage()); } }
public static Map<String, String> loadFromClasspath(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); InputStream stream = PropertiesFileReader.class.getResourceAsStream(fileName); Properties p = new Properties(); try { p.load(stream); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } stream.close(); } catch (Exception e) { throw new EtiqetException("Could not read classpath file " + fileName, e); } return propertyMap; }
PropertiesFileReader { public static Map<String, String> loadFromClasspath(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); InputStream stream = PropertiesFileReader.class.getResourceAsStream(fileName); Properties p = new Properties(); try { p.load(stream); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } stream.close(); } catch (Exception e) { throw new EtiqetException("Could not read classpath file " + fileName, e); } return propertyMap; } }
PropertiesFileReader { public static Map<String, String> loadFromClasspath(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); InputStream stream = PropertiesFileReader.class.getResourceAsStream(fileName); Properties p = new Properties(); try { p.load(stream); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } stream.close(); } catch (Exception e) { throw new EtiqetException("Could not read classpath file " + fileName, e); } return propertyMap; } private  PropertiesFileReader(); }
PropertiesFileReader { public static Map<String, String> loadFromClasspath(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); InputStream stream = PropertiesFileReader.class.getResourceAsStream(fileName); Properties p = new Properties(); try { p.load(stream); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } stream.close(); } catch (Exception e) { throw new EtiqetException("Could not read classpath file " + fileName, e); } return propertyMap; } private  PropertiesFileReader(); static Config loadPropertiesFile(String fileName); static Map<String, String> loadFromClasspath(String fileName); }
PropertiesFileReader { public static Map<String, String> loadFromClasspath(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); InputStream stream = PropertiesFileReader.class.getResourceAsStream(fileName); Properties p = new Properties(); try { p.load(stream); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } stream.close(); } catch (Exception e) { throw new EtiqetException("Could not read classpath file " + fileName, e); } return propertyMap; } private  PropertiesFileReader(); static Config loadPropertiesFile(String fileName); static Map<String, String> loadFromClasspath(String fileName);  }