ByteArrayHolder { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Arrays.hashCode(data); return result; } ByteArrayHolder(byte[] data); byte[] getData(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testHashCode() { byte[] data1a = "hello world".getBytes(); byte[] data1b = new String("hello world").getBytes(); byte[] data2 = "hello another world".getBytes(); ByteArrayHolder rawText1a = new ByteArrayHolder(data1a); ByteArrayHolder rawText1b = new ByteArrayHolder(data1b); Assert.assertEquals(rawText1a.hashCode(), rawText1b.hashCode()); ByteArrayHolder rawText2 = new ByteArrayHolder(data2); Assert.assertNotEquals(rawText1a.hashCode(), rawText2.hashCode()); ByteArrayHolder rawText3 = new ByteArrayHolder(null); Assert.assertNotEquals(rawText1a.hashCode(), rawText3.hashCode()); Assert.assertNotEquals(rawText2.hashCode(), rawText3.hashCode()); }