carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/CombinableMatcher.java
changeset 636 3ef299ba838f
equal deleted inserted replaced
635:8d56403172bc 636:3ef299ba838f
       
     1 package org.junit.internal.matchers;
       
     2 
       
     3 import static org.hamcrest.CoreMatchers.allOf;
       
     4 import static org.hamcrest.CoreMatchers.anyOf;
       
     5 import org.hamcrest.BaseMatcher;
       
     6 import org.hamcrest.Description;
       
     7 import org.hamcrest.Matcher;
       
     8 
       
     9 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 }