SnmpConfigurationImpl implements SnmpConfiguration { @Override public int hashCode() { return (new HashCodeBuilder()) .append(getTargetAddress()) .append(getCommunity()) .append(getLocalPort()) .toHashCode(); } SnmpConfigurationImpl();   SnmpConfigurationImpl(InetAddress address, String community); @Override InetAddress getTargetAddress(); @Override String getCommunity(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int getLocalPort();  }
@Test public void testHashcode() throws Exception { SnmpConfiguration s1 = new SnmpConfigurationImpl(InetAddress.getByAddress(new byte[] { (byte)0xc0, (byte)0xa8, 0x01, 0x01 }), "dummy"); SnmpConfiguration s2 = new SnmpConfigurationImpl(InetAddress.getByAddress(new byte[] { (byte)0xc0, (byte)0xa8, 0x01, 0x01 }), "dummy"); SnmpConfiguration s3 = new SnmpConfigurationImpl(InetAddress.getByAddress(new byte[] { (byte)0xc0, (byte)0xa8, 0x01, 0x02 }), "dummy"); SnmpConfiguration s4 = new SnmpConfigurationImpl(InetAddress.getByAddress(new byte[] { (byte)0xc0, (byte)0xa8, 0x01, 0x01 }), "foo"); Assert.assertTrue(s1.hashCode() == s2.hashCode()); Assert.assertFalse(s1.hashCode() == s3.hashCode()); Assert.assertFalse(s1.hashCode() == s4.hashCode()); }