Top Description Fields Constructors Methods
org.hamcrest

public abstract Class TypeSafeDiagnosingMatcher<T>

extends BaseMatcher<T>
Class Inheritance
Known Direct Subclasses
org.hamcrest.beans.HasPropertyWithValue, org.hamcrest.collection.IsIterableContainingInAnyOrder, org.hamcrest.collection.IsIterableContainingInOrder, org.hamcrest.collection.IsIterableContainingInRelativeOrder, org.hamcrest.core.CombinableMatcher, org.hamcrest.core.Every, org.hamcrest.core.IsCollectionContaining, org.hamcrest.core.IsIterableContaining, org.hamcrest.core.StringRegularExpression, org.hamcrest.object.HasEqualValues, org.hamcrest.object.IsEventFrom, org.hamcrest.xml.HasXPath, org.hamcrest.FeatureMatcher
Imports
org.hamcrest.internal.ReflectiveTypeFinder

Convenient base class for Matchers that require a non-null value of a specific type and that will report why the received value has been rejected. This implements the null check, checks the type and then casts. To use, implement
matchesSafely()
.
Authors
Neil Dunn, Nat Pryce, Steve Freeman

Field Summary

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

Constructor Summary

AccessConstructor and Description
protected
TypeSafeDiagnosingMatcher(Class<?>
The expectedType of the actual value.
expectedType
)

Use this constructor if the subclass that implements matchesSafely is not the class that binds <T> to a type.

protected
TypeSafeDiagnosingMatcher(ReflectiveTypeFinder
A type finder to extract the type
typeFinder
)

Use this constructor if the subclass that implements matchesSafely is not the class that binds <T> to a type.

protected
TypeSafeDiagnosingMatcher()

The default constructor for simple sub types

Method Summary

Modifier and TypeMethod and Description
public final void
describeMismatch(Object
The item that the Matcher has rejected.
item
,
Description
The description to be built or appended to.
mismatchDescription
)

Overrides org.hamcrest.BaseMatcher.describeMismatch.

Implements org.hamcrest.Matcher.describeMismatch.

Generate a description of why the matcher has not accepted the item.
public final boolean
matches(Object
the object against which the matcher is evaluated.
item
)

Implements org.hamcrest.Matcher.matches.

Evaluates the matcher for argument item.
protected abstract boolean
matchesSafely(T item, Description mismatchDescription)

Subclasses should implement this.

Inherited from org.hamcrest.BaseMatcher:
_dont_implement_Matcher___instead_extend_BaseMatcher_isNotNulltoString

Field Detail

expectedTypeback to summary
private final Class<?> expectedType
TYPE_FINDERback to summary
private static final ReflectiveTypeFinder TYPE_FINDER

Constructor Detail

TypeSafeDiagnosingMatcherback to summary
protected TypeSafeDiagnosingMatcher(Class<?> expectedType)

Use this constructor if the subclass that implements matchesSafely is not the class that binds <T> to a type.

Parameters
expectedType:Class<?>

The expectedType of the actual value.

TypeSafeDiagnosingMatcherback to summary
protected TypeSafeDiagnosingMatcher(ReflectiveTypeFinder typeFinder)

Use this constructor if the subclass that implements matchesSafely is not the class that binds <T> to a type.

Parameters
typeFinder:ReflectiveTypeFinder

A type finder to extract the type

TypeSafeDiagnosingMatcherback to summary
protected TypeSafeDiagnosingMatcher()

The default constructor for simple sub types

Method Detail

describeMismatchback to summary
public final void describeMismatch(Object item, Description mismatchDescription)

Overrides org.hamcrest.BaseMatcher.describeMismatch.

Implements org.hamcrest.Matcher.describeMismatch.

Doc from org.hamcrest.Matcher.describeMismatch.

Generate a description of why the matcher has not accepted the item. The description will be part of a larger description of why a matching failed, so it should be concise. This method assumes that matches(item) is false, but will not check this.

Parameters
item:Object

The item that the Matcher has rejected.

mismatchDescription:Description

The description to be built or appended to.

Annotations
@SuppressWarnings:unchecked
@Override
matchesback to summary
public final boolean matches(Object item)

Implements org.hamcrest.Matcher.matches.

Doc from org.hamcrest.Matcher.matches.

Evaluates the matcher for argument item. This method matches against Object, instead of the generic type T. This is because the caller of the Matcher does not know at runtime what the type is (because of type erasure with Java generics). It is down to the implementations to check the correct type.

Parameters
item:Object

the object against which the matcher is evaluated.

Returns:boolean

true if item matches, otherwise false.

Annotations
@Override
@SuppressWarnings:unchecked
matchesSafelyback to summary
protected abstract boolean matchesSafely(T item, Description mismatchDescription)

Subclasses should implement this. The item will already have been checked for the specific type and will never be null.