Client { @Override public boolean equals(Object other) { if (!(other instanceof Client)) return false; if (other == this) return true; Client client = (Client) other; return Objects.equal(id, client.id) && Objects.equal(type, client.type); } protected  Client(String id, String type); final String getId(); final String getType(); @Override boolean equals(Object other); @Override int hashCode(); abstract R accept(ClientVisitor<P,R> visitor, P param);  }
@Test public final void testEquals() { DummyClient client1 = new DummyClient("0", "source1"); DummyClient client2 = new DummyClient("0", "source1"); DummyClient client3 = new DummyClient("1", "source1"); DummyClient client4 = new DummyClient("0", "source2"); Assert.assertEquals(client1, client1); Assert.assertEquals(client1, client2); Assert.assertNotEquals(client1, client3); Assert.assertNotEquals(client1, client4); Assert.assertNotEquals(client1, null); Assert.assertNotEquals(client1, new Object()); Assert.assertEquals(client1.hashCode(), client1.hashCode()); Assert.assertEquals(client1.hashCode(), client2.hashCode()); Assert.assertNotEquals(client1.hashCode(), client3.hashCode()); Assert.assertNotEquals(client1.hashCode(), client4.hashCode()); }