类 IsInstanceOf
- java.lang.Object
- org.hamcrest.BaseMatcher<T>
- org.hamcrest.DiagnosingMatcher<Object>
- org.hamcrest.core.IsInstanceOf
- 所有已实现的接口:
Matcher<Object>
,SelfDescribing
public class IsInstanceOf extends DiagnosingMatcher<Object>
Tests whether the value is an instance of a class. Classes of basic types will be converted to the relevant "Object" classes
构造器概要
构造器 构造器 说明 IsInstanceOf(Class<?> expectedClass)
Creates a new instance of IsInstanceOf
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 static <T> Matcher<T>
any(Class<T> type)
Creates a matcher that matches when the examined object is an instance of the specifiedtype
, as determined by calling theClass.isInstance(Object)
method on that type, passing the the examined object.void
describeTo(Description description)
Generates a description of the object.static <T> Matcher<T>
instanceOf(Class<?> type)
Creates a matcher that matches when the examined object is an instance of the specifiedtype
, as determined by calling theClass.isInstance(Object)
method on that type, passing the the examined object.protected boolean
matches(Object item, Description mismatch)
从类继承的方法 org.hamcrest.DiagnosingMatcher
describeMismatch, matches
从类继承的方法 org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString
构造器详细资料
IsInstanceOf
public IsInstanceOf(Class<?> expectedClass)
Creates a new instance of IsInstanceOf- 参数:
expectedClass
- The predicate evaluates to true for instances of this class or one of its subclasses.
方法详细资料
matches
protected boolean matches(Object item, Description mismatch)
- 指定者:
matches
在类中DiagnosingMatcher<Object>
describeTo
public void describeTo(Description description)
从接口复制的说明:SelfDescribing
Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.- 参数:
description
- The description to be built or appended to.
instanceOf
public static <T> Matcher<T> instanceOf(Class<?> type)
Creates a matcher that matches when the examined object is an instance of the specifiedtype
, as determined by calling theClass.isInstance(Object)
method on that type, passing the the examined object.The created matcher assumes no relationship between specified type and the examined object.
For example:assertThat(new Canoe(), instanceOf(Paddlable.class));
any
public static <T> Matcher<T> any(Class<T> type)
Creates a matcher that matches when the examined object is an instance of the specifiedtype
, as determined by calling theClass.isInstance(Object)
method on that type, passing the the examined object.The created matcher forces a relationship between specified type and the examined object, and should be used when it is necessary to make generics conform, for example in the JMock clause
For example:with(any(Thing.class))
assertThat(new Canoe(), instanceOf(Canoe.class));