ExtensionConfiguration { @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final ExtensionConfiguration that = (ExtensionConfiguration) o; if (!extensionName.equals(that.extensionName)) return false; if (!namespace.equals(that.namespace)) return false; if (!new HierarchicalConfigurationComparator().compare(this.getConfiguration(), that.getConfiguration())) return false; return true; } 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 shouldEqual() { HierarchicalConfiguration hc1 = new HierarchicalConfiguration(); hc1.addProperty("key1", "value1"); hc1.addProperty("key2", "value2"); ExtensionConfiguration config1 = new ExtensionConfiguration("ns", "name", hc1); HierarchicalConfiguration hc2 = new HierarchicalConfiguration(); hc2.addProperty("key1", "value1"); hc2.addProperty("key2", "value2"); ExtensionConfiguration config2 = new ExtensionConfiguration("ns", "name", hc2); Assert.assertTrue(config1.equals(config2)); }
@Test public void shouldNotEqualWhenValuesInConfigAreDifferent() { HierarchicalConfiguration hc1 = new HierarchicalConfiguration(); hc1.addProperty("key1", "value1"); hc1.addProperty("key2", "value2"); ExtensionConfiguration config1 = new ExtensionConfiguration("ns", "name", hc1); HierarchicalConfiguration hc2 = new HierarchicalConfiguration(); hc2.addProperty("key1", "value1"); hc2.addProperty("key2", "value-not the same"); ExtensionConfiguration config2 = new ExtensionConfiguration("ns", "name", hc2); Assert.assertFalse(config1.equals(config2)); }
@Test public void shouldNotEqualWhenMissingKeyInConfig() { HierarchicalConfiguration hc1 = new HierarchicalConfiguration(); hc1.addProperty("key1", "value1"); hc1.addProperty("key2", "value2"); ExtensionConfiguration config1 = new ExtensionConfiguration("ns", "name", hc1); HierarchicalConfiguration hc2 = new HierarchicalConfiguration(); hc2.addProperty("key1", "value1"); ExtensionConfiguration config2 = new ExtensionConfiguration("ns", "name", hc2); Assert.assertFalse(config1.equals(config2)); }
@Test public void shouldNotEqualWhenConfig1HasKeyConfig2DoesNot() { HierarchicalConfiguration hc1 = new HierarchicalConfiguration(); hc1.addProperty("key1", "value1"); hc1.addProperty("key2", "value2"); ExtensionConfiguration config1 = new ExtensionConfiguration("ns", "name", hc1); HierarchicalConfiguration hc2 = new HierarchicalConfiguration(); hc2.addProperty("key1", "value1"); hc2.addProperty("new-key", "value1"); ExtensionConfiguration config2 = new ExtensionConfiguration("ns", "name", hc2); Assert.assertFalse(config1.equals(config2)); }
@Test public void shouldNotEqualWhenConfig2HasAllKeysFromConfig1ButAlsoANewOne() { HierarchicalConfiguration hc1 = new HierarchicalConfiguration(); hc1.addProperty("key1", "value1"); ExtensionConfiguration config1 = new ExtensionConfiguration("ns", "name", hc1); HierarchicalConfiguration hc2 = new HierarchicalConfiguration(); hc2.addProperty("key1", "value1"); hc2.addProperty("new-key", "value1"); ExtensionConfiguration config2 = new ExtensionConfiguration("ns", "name", hc2); Assert.assertFalse(config1.equals(config2)); }
@Test public void shouldNotEqualWhenValuesInConfigAreDifferentDeeperInHierarchy() { HierarchicalConfiguration hc1 = new HierarchicalConfiguration(); hc1.addProperty("key1", "value1"); HierarchicalConfiguration hc1i = new HierarchicalConfiguration(); hc1i.addProperty("key2i", "value2i"); hc1.addProperty("key2", hc1i); ExtensionConfiguration config1 = new ExtensionConfiguration("ns", "name", hc1); HierarchicalConfiguration hc2 = new HierarchicalConfiguration(); hc2.addProperty("key1", "value1"); HierarchicalConfiguration hc2i = new HierarchicalConfiguration(); hc2i.addProperty("key2i", "value-not the same"); hc2.addProperty("key2", hc2i); ExtensionConfiguration config2 = new ExtensionConfiguration("ns", "name", hc2); Assert.assertFalse(config1.equals(config2)); }
@Test public void shouldEqualWhenValuesInConfigAreSameDeeperInHierarchy() { HierarchicalConfiguration hc1 = new HierarchicalConfiguration(); hc1.addProperty("key1", "value1"); HierarchicalConfiguration hc1i = new HierarchicalConfiguration(); hc1i.addProperty("key2i", "value2i"); hc1.addProperty("key2", hc1i); ExtensionConfiguration config1 = new ExtensionConfiguration("ns", "name", hc1); HierarchicalConfiguration hc2 = new HierarchicalConfiguration(); hc2.addProperty("key1", "value1"); HierarchicalConfiguration hc2i = new HierarchicalConfiguration(); hc2i.addProperty("key2i", "value2i"); hc2.addProperty("key2", hc2i); ExtensionConfiguration config2 = new ExtensionConfiguration("ns", "name", hc2); Assert.assertTrue(config1.equals(config2)); }