aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/junit/internal/matchers/CombinableMatcher.java
blob: e9e6947c3ae226f4d20e7e232670d4e6608d31a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package org.junit.internal.matchers;

import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.anyOf;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;

public class CombinableMatcher<T> extends BaseMatcher<T> {

	private final Matcher<? extends T> fMatcher;

	public CombinableMatcher(Matcher<? extends T> matcher) {
		fMatcher= matcher;
	}

	public boolean matches(Object item) {
		return fMatcher.matches(item);
	}

	public void describeTo(Description description) {
		description.appendDescriptionOf(fMatcher);
	}
	
	@SuppressWarnings("unchecked")
	public CombinableMatcher<T> and(Matcher<? extends T> matcher) {
		return new CombinableMatcher<T>(allOf(matcher, fMatcher));
	}

	@SuppressWarnings("unchecked")
	public CombinableMatcher<T> or(Matcher<? extends T> matcher) {
		return new CombinableMatcher<T>(anyOf(matcher, fMatcher));
	}
}