Skip to content

Commit d8b4cef

Browse files
author
joeretro
committed
Added hasItems(T...) convenience method
1 parent 3290087 commit d8b4cef

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/library/org/hamcrest/collection/IsCollectionContaining.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,13 @@ public static <T> Matcher<Iterable<T>> hasItems(Matcher<T>... elementMatchers) {
5050
return allOf(all);
5151
}
5252

53+
@Factory
54+
public static <T> Matcher<Iterable<T>> hasItems(T... elements) {
55+
Collection<Matcher<Iterable<T>>> all = new ArrayList<Matcher<Iterable<T>>>(elements.length);
56+
for (T element : elements) {
57+
all.add(hasItem(element));
58+
}
59+
return allOf(all);
60+
}
61+
5362
}

src/unit-test/org/hamcrest/collection/IsCollectionContainingTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public void testMatchesAllItemsInCollection() {
3838
assertMatches("should match list containing all of items",
3939
hasItems(equalTo("a"), equalTo("b"), equalTo("c")),
4040
asList("a", "b", "c"));
41+
assertMatches("should match list containing all of items (without matchers)",
42+
hasItems("a", "b", "c"),
43+
asList("a", "b", "c"));
4144
assertMatches("should match list containing all of items in any order",
4245
hasItems(equalTo("a"), equalTo("b"), equalTo("c")),
4346
asList("c", "b", "a"));

0 commit comments

Comments
 (0)