Domain extends AbstractEntity<Integer> { @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!(obj instanceof Domain)) { return false; } if (!this.getClass().equals(obj.getClass())) { return false; } final Domain other = (Domain) obj; if (this.id != null && other.id != null) { return Objects.equals(this.id, other.id); } else { return Objects.equals(this.code, other.code); } } Domain();  Domain(final String code, final String name); @Override Integer getId(); @Override void setId(final Integer id); String getType(); String getCode(); void setCode(final String code); String getName(); void setName(final String name); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); static final String ATTRIBUTE_NAME; static final String ATTRIBUTE_CODE; }
@Test public void testEquals() { Country c1 = new Country("NL", "Nederland"); c1.setId(1); Country c2 = new Country("NL", "Nederland"); c2.setId(1); Country c3 = new Country("NL", "Nederland"); Country c4 = new Country("NL", "Nederland"); Region r1 = new Region(null, "Europe"); r1.setId(1); assertFalse(c1.equals(null)); assertFalse(c1.equals(new Object())); assertFalse(c1.equals(r1)); assertTrue(c1.equals(c2)); assertTrue(c3.equals(c4)); assertTrue(c1.equals(c4)); }