public void testPlaceholderReplacement() { PropertiesHelper.resolvePlaceHolders(props); String str = PropertiesHelper.getString("my.nonexistent.prop", props, "did.not.exist"); assertEquals("did.not.exist", str); str = PropertiesHelper.getString("my.nonexistent.prop", props, null); assertNull(str); str = PropertiesHelper.getString("my.string.prop", props, "na"); assertEquals("replacement did not occur", "string", str); str = PropertiesHelper.getString("my.string.prop", props, "did.not.exist"); assertEquals("replacement did not occur", "string", str); boolean bool = PropertiesHelper.getBoolean("my.nonexistent.prop", props); assertFalse("non-exists as boolean", bool); bool = PropertiesHelper.getBoolean("my.nonexistent.prop", props, false); assertFalse("non-exists as boolean", bool); bool = PropertiesHelper.getBoolean("my.nonexistent.prop", props, true); assertTrue("non-exists as boolean", bool); bool = PropertiesHelper.getBoolean("my.boolean.prop", props); assertTrue("boolean replacement did not occur", bool); bool = PropertiesHelper.getBoolean("my.boolean.prop", props, false); assertTrue("boolean replacement did not occur", bool); int i = PropertiesHelper.getInt("my.nonexistent.prop", props, -1); assertEquals(-1, i); i = PropertiesHelper.getInt("my.int.prop", props, 100); assertEquals(1, i); Integer I = PropertiesHelper.getInteger("my.nonexistent.prop", props); assertNull(I); I = PropertiesHelper.getInteger("my.integer.prop", props); assertEquals(I, new Integer(1)); str = props.getProperty("partial.prop1"); assertEquals("partial replacement (ends)", "tmp/middle/dir/tmp.txt", str); str = props.getProperty("partial.prop2"); assertEquals("partial replacement (midst)", "basedir/tmp/myfile.txt", str); }
public void testParseExceptions() { boolean b = PropertiesHelper.getBoolean("parse.error", props); assertFalse("parse exception case - boolean", b); try { PropertiesHelper.getInt("parse.error", props, 20); fail("parse exception case - int"); } catch (NumberFormatException expected) { } try { PropertiesHelper.getInteger("parse.error", props); fail("parse exception case - Integer"); } catch (NumberFormatException expected) { } }