ExtensionConfiguration { public Map<String, String> tryGetMapFromConfiguration() { Map<String, String> map = new HashMap<String, String>(); try { final Iterator keys = this.configuration.getKeys(); while (keys.hasNext()) { final String key = keys.next().toString(); map.put(key, this.configuration.getString(key)); } } catch (Exception ex) { logger.error("There is an error in the configuration of this extension [" + this.namespace + ":" + this.extensionName + "]. All values must be of a String data type."); map = null; } return map; } ExtensionConfiguration(final String namespace, final String extensionName, final HierarchicalConfiguration extensionConfiguration); String getNamespace(); String getExtensionName(); HierarchicalConfiguration getConfiguration(); Map<String, String> tryGetMapFromConfiguration(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void tryGetMapFromConfigurationEmptyConfig() { HierarchicalConfiguration hc = new HierarchicalConfiguration(); ExtensionConfiguration config = new ExtensionConfiguration("ns", "name", hc); Map<String, String> map = config.tryGetMapFromConfiguration(); Assert.assertNotNull(map); Assert.assertTrue(map.isEmpty()); }
@Test public void tryGetMapFromConfigurationBadConfig() { HierarchicalConfiguration hc = new HierarchicalConfiguration(); HierarchicalConfiguration innerHc = new HierarchicalConfiguration(); innerHc.addProperty("test", "1"); hc.addProperty("test-bad", innerHc); ExtensionConfiguration config = new ExtensionConfiguration("ns", "name", hc); Map<String, String> map = config.tryGetMapFromConfiguration(); Assert.assertNull(map); }
@Test public void tryGetMapFromConfigurationNiceConfig() { HierarchicalConfiguration hc = new HierarchicalConfiguration(); hc.addProperty("key1", "value1"); hc.addProperty("key2", "value2"); ExtensionConfiguration config = new ExtensionConfiguration("ns", "name", hc); Map<String, String> map = config.tryGetMapFromConfiguration(); Assert.assertNotNull(map); Assert.assertTrue(map.containsKey("key1")); Assert.assertEquals("value1", map.get("key1")); Assert.assertTrue(map.containsKey("key2")); Assert.assertEquals("value2", map.get("key2")); }