Endpoint { @Override public boolean equals(final Object otherInstance) { if (otherInstance == null || !(otherInstance instanceof Endpoint)) { return false; } final Endpoint other = (Endpoint) otherInstance; if (!this.name.equals(other.name) || !this.host.equals(other.host) || this.port != other.port) { return false; } return true; } Endpoint(final String name, final String host, final int port); String getName(); String getHost(); int getPort(); @Override boolean equals(final Object otherInstance); @Override int hashCode(); @Override String toString();  }
@Test public void testEquals() { final Endpoint a = new Endpoint("foo", "bar", 1); final Endpoint b = new Endpoint("foo", "bar", 1); assertThat(a.equals(b), is(true)); assertThat(b.equals(a), is(true)); assertThat(b.hashCode(), is(a.hashCode())); final Endpoint c = new Endpoint("bar", "foo", 1); assertThat(a.equals(c), is(false)); assertThat(b.equals(c), is(false)); final Endpoint d = new Endpoint("foo", "bar", 2); assertThat(a.equals(d), is(false)); final Endpoint e = new Endpoint("foo", "baz", 1); assertThat(a.equals(e), is(false)); assertThat(a.equals(null), is(false)); assertThat(a.equals("some string"), is(false)); }