M_x_r
M_x_r

Reputation: 604

assertarrayequals

I am testing two arrays in Junit 4 to see if they are equal and get the error:

arrays first differed at element [0]; expected: com.scheduling.Process<(Background, 1000)> but was: com.scheduling.Process<(Background, 1000)>

I know this is very little information to go on. I have read elsewhere that assertArrayEquals looks at references within the array.

Should something like assertArrayEquals(new Cat(), new Cat()) return equal (given that the Cat class implements comparable)? Or will assertArrayEquals deem the two Cat objects different as they are not linked by a reference?

Upvotes: 2

Views: 3703

Answers (1)

BoppreH
BoppreH

Reputation: 10173

It compares using equals. You can check that by running

Assert.assertArrayEquals(new Object[]{new Integer(1)}, new Object[]{new Integer(1)});

Or by creating a class that just implements the method equals.

Even though the two objects are different instances, the arrays still compare correctly.

Upvotes: 2

Related Questions