Note that assertEquals also works directly with lists and sets. This takes a lot less typing and it will give very clear error messages.
If return values ββare not allowed to contain duplicates, they should return a set instead of a list. If you can change the function you are testing, you can test it as follows:
assertEquals(new HashSet<>(Arrays.asList("Item1", "Item2")), get_products());
If this is not an option, you should sort both expected and actual results and compare them:
asssertEquals(Arrays.sort(Arrays.asList("Item1", "Item2")), Arrays.sort(get_products()));
Finally, you can resort to using Hamcrest sockets (the containsInAnyOrder function is in org.hamcrest.collection.IsIterableContainingInAnyOrder ):
assertThat(get_products(), containsInAnyOrder("Item1", "Item2"));
Thirler
source share