Created
July 22, 2015 15:24
-
-
Save pjdietz/f9d90ece026de580747a to your computer and use it in GitHub Desktop.
ArgumentMatcher for checking if two collection contains the same elements.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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