Top Description Fields Constructors Methods
org.hamcrest.core

public Class IsInstanceOf

extends DiagnosingMatcher<Object>
Class Inheritance
Imports
org.hamcrest.Description, .DiagnosingMatcher, .Factory, .Matcher

Tests whether the value is an instance of a class. Classes of basic types will be converted to the relevant "Object" classes

Field Summary

Modifier and TypeField and Description
private final Class<?>
private final Class<?>

Constructor Summary

AccessConstructor and Description
public
IsInstanceOf(Class<?>
The predicate evaluates to true for instances of this class or one of its subclasses.
expectedClass
)

Creates a new instance of IsInstanceOf

Method Summary

Modifier and TypeMethod and Description
public static <T> Matcher<T>
any(Class<T> type)

Creates a matcher that matches when the examined object is an instance of the specified type, as determined by calling the java.lang.Class#isInstance(Object) method on that type, passing the the examined object.

public void
describeTo(Description
The description to be built or appended to.
description
)

Implements org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object.
public static <T> Matcher<T>
instanceOf(Class<?> type)

Creates a matcher that matches when the examined object is an instance of the specified type, as determined by calling the java.lang.Class#isInstance(Object) method on that type, passing the the examined object.

private static Class<?>
matchableClass(Class<?> expectedClass)

protected boolean
Inherited from org.hamcrest.DiagnosingMatcher:
describeMismatchmatches

Field Detail

expectedClassback to summary
private final Class<?> expectedClass
matchableClassback to summary
private final Class<?> matchableClass

Constructor Detail

IsInstanceOfback to summary
public IsInstanceOf(Class<?> expectedClass)

Creates a new instance of IsInstanceOf

Parameters
expectedClass:Class<?>

The predicate evaluates to true for instances of this class or one of its subclasses.

Method Detail

anyback to summary
public static <T> Matcher<T> any(Class<T> type)

Creates a matcher that matches when the examined object is an instance of the specified type, as determined by calling the java.lang.Class#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 with(any(Thing.class))

For example:

assertThat(new Canoe(), instanceOf(Canoe.class));
Annotations
@SuppressWarnings:unchecked
@Factory
describeToback to summary
public void describeTo(Description description)

Implements org.hamcrest.SelfDescribing.describeTo.

Doc from org.hamcrest.SelfDescribing.describeTo.

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.

Parameters
description:Description

The description to be built or appended to.

Annotations
@Override
instanceOfback to summary
public static <T> Matcher<T> instanceOf(Class<?> type)

Creates a matcher that matches when the examined object is an instance of the specified type, as determined by calling the java.lang.Class#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));
Annotations
@SuppressWarnings:unchecked
@Factory
matchableClassback to summary
private static Class<?> matchableClass(Class<?> expectedClass)
matchesback to summary
protected boolean matches(Object item, Description mismatch)

Implements abstract org.hamcrest.DiagnosingMatcher.matches.

Annotations
@Override