PropertyFileDAO { public boolean getPropertyBoolean(String propertyFileName, String propertyName) throws PropertyAccessException { PropertiesConfiguration properties = propertyFilesHashmap.get(propertyFileName); if (properties != null && properties.containsKey(propertyName)) { try { return properties.getBoolean(propertyName); } catch (ConversionException ex) { LOG.warn("Could not read property {}: {}", propertyName, ex.getLocalizedMessage(), ex); String sProp = properties.getString(propertyName); if (NullChecker.isNotNullish(sProp)) { return sProp.equalsIgnoreCase("t"); } } } throw new PropertyAccessException(getErrorMessage(propertyFileName, propertyName)); } PropertyFileDAO(); void loadPropertyFile(File propertyFile, String propertyFileName); String getProperty(String propertyFileName, String propertyName); void setProperty(String propertyFileName, String key, Object value); String getPropertyComment(String propertyFileName, String key); boolean getPropertyBoolean(String propertyFileName, String propertyName); long getPropertyLong(String propertyFileName, String propertyName); Long getPropertyLongObject(String propertyFileName, String propertyName, Long defaultValue); Set<String> getPropertyNames(String propertyFileName); Properties getProperties(String propertyFileName); void printToLog(String propertyFileName); boolean containsPropFile(String fileName);  }
@Test public void testGetPropertyBoolean() throws PropertyAccessException { PropertyFileDAO propDAO = loadTestProperties(); assertTrue(propDAO.getPropertyBoolean(TEST_PROPERTIES_NAME, "booleanTrueTest")); assertTrue(propDAO.getPropertyBoolean(TEST_PROPERTIES_NAME, "booleanTrueTest2")); assertFalse(propDAO.getPropertyBoolean(TEST_PROPERTIES_NAME, "booleanFalseTest")); assertFalse(propDAO.getPropertyBoolean(TEST_PROPERTIES_NAME, "booleanFalseTest2")); }
@Test(expected = PropertyAccessException.class) public void testGetPropertyBoolean_EmptyBooleanValue() throws PropertyAccessException { PropertyFileDAO propDAO = loadTestProperties(); propDAO.getPropertyBoolean(TEST_PROPERTIES_NAME, "booleanErrorTest"); }
@Test(expected = PropertyAccessException.class) public void testGetPropertyBoolean_MissingField() throws PropertyAccessException { PropertyFileDAO propDAO = loadTestProperties(); propDAO.getPropertyBoolean(TEST_PROPERTIES_NAME, "nonexistantfield"); }
@Test(expected = PropertyAccessException.class) public void testGetPropertyBoolean_NoPropertyFile() throws PropertyAccessException { PropertyFileDAO propDAO = loadTestProperties(); propDAO.getPropertyBoolean("nonexistant", "nonexistantfield"); }