Package org.hamcrest.core
Class IsInstanceOf
- java.lang.Object
- org.hamcrest.BaseMatcher<T>
- org.hamcrest.DiagnosingMatcher<Object>
- org.hamcrest.core.IsInstanceOf
- All Implemented Interfaces:
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
Constructor Summary
Constructors Constructor Description IsInstanceOf(Class<?> expectedClass)Creates a new instance of IsInstanceOf
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.voiddescribeTo(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 booleanmatches(Object item, Description mismatch)Methods inherited from class org.hamcrest.DiagnosingMatcher
describeMismatch, matches
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString
Constructor Detail
IsInstanceOf
public IsInstanceOf(Class<?> expectedClass)
Creates a new instance of IsInstanceOf- Parameters:
expectedClass- The predicate evaluates to true for instances of this class or one of its subclasses.
Method Detail
matches
protected boolean matches(Object item, Description mismatch)
- Specified by:
matchesin classDiagnosingMatcher<Object>
describeTo
public void describeTo(Description description)
Description copied from interface:SelfDescribingGenerates 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.- Parameters:
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));