How would you succinctly assert the equality of Collection elements, specifically a Set in JUnit 4?
with hamcrest:
assertThat(s1, is(s2));
with plain assert:
assertEquals(s1, s2);
NB:t the equals() method of the concrete set class is used
As an additional method that is array based ... you can consider using unordered array assertions in junitx . Although the Apache CollectionUtils example will work, there is a pacakge of solid assertion extensions there as well :
I think that the
ArrayAssert.assertEquivalenceArrays(new Integer[]{1,2,3}, new Integer[]{1,3,2});
approach will be much more readable and debuggable for you (all Collections support toArray(), so it should be easy enough to use the ArrayAssert methods.
Of course the downside here is that, junitx is an additional jar file or maven entry...
<dependency org="junit-addons" name="junit-addons" rev="1.4"/>
Check this article. One example from there:
@Test
public void listEquality() {
List<Integer> expected = new ArrayList<Integer>();
expected.add(5);
List<Integer> actual = new ArrayList<Integer>();
actual.add(5);
assertEquals(expected, actual);
}