I am writing a simple JUnit test for the MyObject
class.
A MyObject
can be created from a static factory met
org.junit.Assert.assertEquals()
and org.junit.Assert.assertArrayEquals()
do the job.
To avoid next questions: If you want to ignore the order put all elements to set and then compare: Assert.assertEquals(new HashSet
If however you just want to ignore duplicates but preserve the order wrap you list with LinkedHashSet
.
Yet another tip. The trick Assert.assertEquals(new HashSet
works fine until the comparison fails. In this case it shows you error message with to string representations of your sets that can be confusing because the order in set is almost not predictable (at least for complex objects). So, the trick I found is to wrap the collection with sorted set instead of HashSet
. You can use TreeSet
with custom comparator.