HostInfo { @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; HostInfo hostInfo = (HostInfo) o; if (!hostname.equals(hostInfo.hostname)) return false; if (services != null ? !services.equals(hostInfo.services) : hostInfo.services != null) return false; return true; } HostInfo(String hostName, Collection<ServiceInfo> services); String getHostname(); Collection<ServiceInfo> getServices(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testEquals() { HostInfo a = new HostInfo("foo.yahoo.com", Arrays.asList(new ServiceInfo("foo", "bar", null, null, "config-id", "host-name"))); HostInfo b = new HostInfo("foo.yahoo.com", Arrays.asList(new ServiceInfo("foo", "bar", null, null, "config-id", "host-name"))); HostInfo c = new HostInfo("foo.yahoo.com", Arrays.asList(new ServiceInfo("foo", "baz", null, null, "config-id", "host-name"))); HostInfo d = new HostInfo("foo.yahoo.com", Arrays.asList(new ServiceInfo("bar", "baz", null, null, "config-id", "host-name"))); HostInfo e = new HostInfo("bar.yahoo.com", null); new EqualsTester() .addEqualityGroup(a, b) .addEqualityGroup(c) .addEqualityGroup(d) .addEqualityGroup(e).testEquals(); }