01: package org.junit.matchers;
02:
03: import static org.hamcrest.CoreMatchers.allOf;
04: import static org.hamcrest.CoreMatchers.anyOf;
05: import org.hamcrest.BaseMatcher;
06: import org.hamcrest.Description;
07: import org.hamcrest.Matcher;
08:
09: public class CombinableMatcher<T> extends BaseMatcher<T> {
10:
11: private final Matcher<? extends T> fMatcher;
12:
13: public CombinableMatcher(Matcher<? extends T> matcher) {
14: fMatcher = matcher;
15: }
16:
17: public boolean matches(Object item) {
18: return fMatcher.matches(item);
19: }
20:
21: public void describeTo(Description description) {
22: description.appendDescriptionOf(fMatcher);
23: }
24:
25: @SuppressWarnings("unchecked")
26: public CombinableMatcher<T> and(Matcher<? extends T> matcher) {
27: return new CombinableMatcher<T>(allOf(matcher, fMatcher));
28: }
29:
30: @SuppressWarnings("unchecked")
31: public CombinableMatcher<T> or(Matcher<? extends T> matcher) {
32: return new CombinableMatcher<T>(anyOf(matcher, fMatcher));
33: }
34: }
|