Question

Java says that the following are not equal while they are:

java.lang.AssertionError: expected:<[[(7,UP), (2,RIGHT)], [(4,DOWN), (11,MIDDLE)], 
[(9,RIGHT), (1,UP)]]>
 but was:<[[(2,RIGHT), (7,UP)], [(11,MIDDLE), (4,DOWN)], [(1,UP), (9,RIGHT)]]>

(where each is a HashSet and each subset is another HashSet)

Was it helpful?

Solution

No code is shown, so these are only guesses.

First, as mentioned, the elements of your Sets don't implement .equals()/.hashCode().

Second, you use assertEquals() on Collections: many test frameworks (TestNG for instance), when faced with Collections as arguments, will succeed if and only if the two collections have the same elements in the same order. Use another method, such as, for instance, assertEqualsNoOrder-) -- but here this is complicated by the fact that you have embedded Collections. Or just use assertTrue(coll1.equals(coll2)).

OTHER TIPS

Most likely, the problem is that the equals() or hashCode() method of the type represented by (7,UP), etc., does not behave the way you expect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top