Package org.hamcrest.core
Class IsInstanceOf
- All Implemented Interfaces:
Matcher<Object>
,SelfDescribing
Tests whether the value is an instance of a class.
Classes of basic types will be converted to the relevant "Object" classes
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Matcher
<T> 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) Evaluates the matcher for argument item.Methods inherited from class org.hamcrest.DiagnosingMatcher
describeMismatch, matches
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
-
Constructor Details
-
IsInstanceOf
Creates a new instance of IsInstanceOf- Parameters:
expectedClass
- The predicate evaluates to true for instances of this class or one of its subclasses.
-
-
Method Details
-
matches
Description copied from class:DiagnosingMatcher
Evaluates the matcher for argument item.- Specified by:
matches
in classDiagnosingMatcher<Object>
- Parameters:
item
- the value to checkmismatch
- the description for the matcher- Returns:
true
if item matches, otherwisefalse
.
-
describeTo
Description copied from interface:SelfDescribing
Generates a description of the object. The description may be part of 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
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));
- Type Parameters:
T
- the matcher type.- Parameters:
type
- the type to check.- Returns:
- The matcher.
-
any
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));
- Type Parameters:
T
- the matcher type.- Parameters:
type
- the type to check.- Returns:
- The matcher.
-