EntityReference implements Serializable, Cloneable, Comparable<EntityReference> { @Override public int hashCode() { return toString().hashCode(); } EntityReference(String name, EntityType type);  EntityReference(String name, EntityType type, EntityReference parent); void setName(String name); String getName(); void setParent(EntityReference parent); EntityReference getParent(); void setChild(EntityReference child); EntityReference getChild(); void setType(EntityType type); EntityType getType(); EntityReference getRoot(); EntityReference extractReference(EntityType type); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); @Override EntityReference clone(); int compareTo(EntityReference reference);  }
@Test public void testHashCode() { EntityReference reference1 = new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI))); Assert.assertEquals(reference1.hashCode(), reference1.hashCode()); EntityReference reference2 = new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI))); Assert.assertEquals(reference1.hashCode(), reference2.hashCode()); EntityReference reference3 = new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE, new EntityReference("wiki2", EntityType.WIKI))); Assert.assertFalse(reference1.hashCode() == reference3.hashCode()); EntityReference reference4 = new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space2", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI))); Assert.assertFalse(reference1.hashCode() == reference4.hashCode()); EntityReference reference5 = new EntityReference("page2", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI))); Assert.assertFalse(reference1.hashCode() == reference5.hashCode()); EntityReference reference6 = new EntityReference("page", EntityType.DOCUMENT, null); Assert.assertFalse(reference1.hashCode() == reference6.hashCode()); Assert.assertEquals(reference6.hashCode(), new EntityReference("page", EntityType.DOCUMENT, null).hashCode()); }