NamespaceAndName { @Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (obj == null) { return false; } else if (obj instanceof NamespaceAndName) { NamespaceAndName nrn = (NamespaceAndName) obj; if ((nrn.getName() == null && name == null) || (nrn.getName().equals(name) && ((nrn.getNamespace() == null && namespace == null) || nrn.getNamespace().equals(namespace)))) { return true; } } return false; } NamespaceAndName(String namespace, String name); String getNamespace(); String getName(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void testEquals() { NamespaceAndName original = new NamespaceAndName("namespace1", "name1"); assertThat(original, is(new NamespaceAndName("namespace1", "name1"))); assertThat(original, is(not(new NamespaceAndName("namespace2", "name1")))); assertThat(original, is(not(new NamespaceAndName("namespace1", "name2")))); assertThat(original, is(not(new NamespaceAndName("namespace2", "name2")))); }