01: package org.junit.matchers;
02:
03: import static org.hamcrest.CoreMatchers.not;
04: import org.hamcrest.BaseMatcher;
05: import org.hamcrest.Description;
06: import org.hamcrest.Matcher;
07: import static org.junit.matchers.IsCollectionContaining.hasItem;
08:
09: public class Each {
10: public static <T> Matcher<Iterable<T>> each(
11: final Matcher<T> individual) {
12: final Matcher<Iterable<T>> allItemsAre = not(hasItem(not(individual)));
13:
14: return new BaseMatcher<Iterable<T>>() {
15: public boolean matches(Object item) {
16: return allItemsAre.matches(item);
17: }
18:
19: public void describeTo(Description description) {
20: description.appendText("each ");
21: individual.describeTo(description);
22: }
23: };
24: }
25: }
|