I was just coding away on a bunch of tests that generated primitive
arrays (int[] in this case) and was meriily going along doing:
Assert.assertEquals(arr1, arr2);
When I ran the test I got a failure and on poking a little bit it's
obvious why. Actually the failure message was a little bit of a hint.
The message looked like this:
java.lang.AssertionError: expected:<[I@20dcb7> but was:<[I@7aa2a8>
Clearly the arrays were getting no special treatment. In fact the
method being called was assertEqual(Object, Object) and so it would
seem it was doing a memory/JVM id equality check.
So I was wondering, is there a particular reason that there are not
assertEquals() methods for arrays of each of the primitive types?
Admittedly it's not that hard to write:
Assert.assertTrue( Arrays.equals(arr1, arr2) );
But I think having the methods on Assert would reduce confusion, and
allow for the output of better default failure messages like:
java.lang.AssertionError: expected:[1,2,3] but was:[3,2,1]
Just a suggestion.
-t