I want to test the result of a java method that returns a Set of elements and I need to check if the result contains exactly all the elements but not necessarily in the same order.
I’m using junit assertThat for the test but I don’t know the matcher to use.
Basically I’m looking for something like JUnitMatchers.hasItem(T ... elements) that fails if at least one of the element returned by the method is not in elements. And since my method returns a set, it would be nice that the matcher fails if elements contains twice the same element.
Does anyone knows such a matcher?
You may use Hamcrest 1.2.1. It has an IsIterableContainingInAnyOrder matcher, which perfectly fits your needs.