Your remove
method does not do what you seem to expect. In particular this:
listArr[0] = listArr[size-1];
changes the order of the elements and therefore the hashcode.
In other words, adding then removing an element does not leave the heap unchanged.
You can iterate over the elements of your two heaps and print them to verify what the difference is.
EDIT
I have slightly amended your test to print the content of your array (which I have made public for this):
public void testhashCode() {
Heap12<Integer> sampleHeap = new Heap12<Integer>(); //instantiate two
sampleHeap.add(100); //add two vales
sampleHeap.add(0);
Heap12<Integer> sampleHeap2 = new Heap12<Integer>(sampleHeap);
assertEquals(sampleHeap.hashCode(), sampleHeap2.hashCode());
System.out.println(Arrays.toString(sampleHeap.listArr));
sampleHeap.add(1000); //make the heaps uneven
System.out.println(Arrays.toString(sampleHeap.listArr));
assertFalse(sampleHeap.hashCode() == sampleHeap2.hashCode());
sampleHeap.remove(); //remove the values added
System.out.println(Arrays.toString(sampleHeap.listArr));
assertTrue(sampleHeap2.equals(sampleHeap));
assertTrue(sampleHeap.hashCode() == sampleHeap2.hashCode());
}
and it outputs:
[100, 0, null, null, null]
[1000, 0, 100, null, null]
[100, 0, 100, null, null]
So adding and removing has left an extra element in your list.