1

I want to assert equality of two collection using hamcrest.

I know there is contains matcher but I want it to ignore ordering.

{1,2} is equals to {2,1} for my need.

What is the right syntax?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

2 Answers2

2

Use containsInAnyOrder() :

  List colors = Arrays.asList("red","green","blue");
  assertThat(colors, containsInAnyOrder("green", "red", "blue")); // is true
Kao
  • 7,225
  • 9
  • 41
  • 65
-1
Collection col1, col2;
Set set1 = new HashSet(col1);
set1.removeAll(col2);
assertTrue(set1.isEmpty());

Also you can create utils class like this and use it to find difference

Meiblorn
  • 2,522
  • 2
  • 18
  • 23