1package org.hamcrest.object; 2 3import org.hamcrest.Description; 4import org.hamcrest.Matcher; 5import org.hamcrest.Factory; 6import org.hamcrest.TypeSafeMatcher; 7 8public class IsCompatibleType<T> extends TypeSafeMatcher<Class<?>> { 9 private final Class<T> type; 10 11 public IsCompatibleType(Class<T> type) { 12 this.type = type; 13 } 14 15 public boolean matchesSafely(Class<?> cls) { 16 return type.isAssignableFrom(cls); 17 } 18 19 public void describeTo(Description description) { 20 description.appendText("type < ").appendText(type.getName()); 21 } 22 23 @Factory 24 public static <T> Matcher<Class<?>> typeCompatibleWith(Class<T> baseType) { 25 return new IsCompatibleType<T>(baseType); 26 } 27} 28