@Test public void testDefaultValues() throws Exception { Configurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("name should equal john","john",conf.getProperty("name")); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertFalse("stored properties should not contain the default value",props.containsKey("name")); manager.populate(conf); assertEquals("default property name should still exist after re-populating","john",conf.getProperty("name")); }
@Test public void testDefaultValues() throws Exception { Configurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("name should equal john","john",conf.getProperty("name")); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertFalse("stored properties should not contain the default value",props.containsKey("name")); manager.populate(conf); assertEquals("default property name should still exist after re-populating","john",conf.getProperty("name")); }
@Test public void testNewValues() throws Exception { Configurable conf = DummyConfigurable.getInstance(); conf.setProperty("country", "france"); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("country should equal france","france",conf.getProperty("country")); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertTrue("stored properties should contain the default value",props.containsKey("country")); assertEquals("stored property country should equal france","france",props.getProperty("country")); manager.populate(conf); assertEquals("default property name should still exist after re-populating","france",conf.getProperty("country")); }
@Test public void testNewValues() throws Exception { Configurable conf = DummyConfigurable.getInstance(); conf.setProperty("country", "france"); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("country should equal france","france",conf.getProperty("country")); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertTrue("stored properties should contain the default value",props.containsKey("country")); assertEquals("stored property country should equal france","france",props.getProperty("country")); manager.populate(conf); assertEquals("default property name should still exist after re-populating","france",conf.getProperty("country")); }
@Test public void testRemoveNotDefaultValue() throws Exception { Configurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); conf.setProperty("hhh", "iii"); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertEquals("The stored file should contain the new entry","iii",props.get("hhh")); conf.deleteProperty("hhh"); manager.store(conf); manager.populate(conf); assertNull("The removed value should no longer exist",conf.getProperty("hhh")); props.clear(); props.load(new FileInputStream(configFile)); assertNull("The stored file should no longer contain the deleted entry",props.get("hhh")); }
@Test public void testRemoveNotDefaultValue() throws Exception { Configurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); conf.setProperty("hhh", "iii"); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertEquals("The stored file should contain the new entry","iii",props.get("hhh")); conf.deleteProperty("hhh"); manager.store(conf); manager.populate(conf); assertNull("The removed value should no longer exist",conf.getProperty("hhh")); props.clear(); props.load(new FileInputStream(configFile)); assertNull("The stored file should no longer contain the deleted entry",props.get("hhh")); }