ByteArrayHolder { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ByteArrayHolder other = (ByteArrayHolder) obj; if (!Arrays.equals(data, other.data)) return false; return true; } ByteArrayHolder(byte[] data); byte[] getData(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testEquals() { byte[] data1a = "hello world".getBytes(); byte[] data1b = new String("hello world").getBytes(); byte[] data2 = "hello another world".getBytes(); ByteArrayHolder rawText1a = new ByteArrayHolder(data1a); Assert.assertEquals(rawText1a, rawText1a); ByteArrayHolder rawText1b = new ByteArrayHolder(data1b); Assert.assertEquals(rawText1a, rawText1b); ByteArrayHolder rawText2 = new ByteArrayHolder(data2); Assert.assertNotEquals(rawText1a, rawText2); ByteArrayHolder rawText3 = new ByteArrayHolder(null); Assert.assertNotEquals(rawText1a, rawText3); Assert.assertNotEquals(rawText3, rawText1a); Assert.assertNotEquals(rawText1a, 42); Assert.assertNotEquals(rawText1a, null); }