Skip to content

Instantly share code, notes, and snippets.

@Inkimar
Created September 14, 2016 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Inkimar/54f85bebad3b8695a5cdf35c58b43d01 to your computer and use it in GitHub Desktop.
Save Inkimar/54f85bebad3b8695a5cdf35c58b43d01 to your computer and use it in GitHub Desktop.
test 2 lists, no regard to order - using hamcrest
import static org.hamcrest.Matchers.containsInAnyOrder;
/**
* http://pragmaticqa.co.uk/blog/2012/10/comparing-lists-with-hamcrest/
*/
@Test
public void TEST_HAMCREST_listTestsWithoutOrder() {
List<String> list1 = new ArrayList<>();
List<String> list2 = new ArrayList<>();
list1.add("red");
list1.add("green");
list1.add("orange");
list2.add("green");
list2.add("orange");
list2.add("red");
assertThat("List equality without order", list1, containsInAnyOrder(list2.toArray()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment