Skip to content

Instantly share code, notes, and snippets.

@pjdietz
Created July 22, 2015 15:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjdietz/f9d90ece026de580747a to your computer and use it in GitHub Desktop.
Save pjdietz/f9d90ece026de580747a to your computer and use it in GitHub Desktop.
ArgumentMatcher for checking if two collection contains the same elements.
class ContainsElements<T> extends ArgumentMatcher<Collection> {
private Collection<T> expected;
public ContainsEqualElements(Collection<T> expected) {
this.expected = expected;
}
public boolean matches(Object list) {
if (list instanceof Collection) {
Collection<T> actual = (Collection<T>) list;
return actual.size() == expected.size() && actual.containsAll(expected) && expected.containsAll(actual);
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment