BoundedDiagnosingMatcher


abstract class BoundedDiagnosingMatcher<S, T : S?> : BaseMatcher


A matcher that allows for a quick creation of a matcher that applies to a given type but only processes items of a specific subtype of that matcher. Additional interfaces can be applied. This class is syntactic sugar for instanceOf where the first argument is the base class and the remaining optional arguments are interfaces.

Parameters
<S>

The desired type of the Matcher (T or a subclass of T).

<T : S?>

The actual type that the matcher applies safely to.

Summary

Public constructors

BoundedDiagnosingMatcher(expectedType: Class<S!>!)
BoundedDiagnosingMatcher(
    expectedType: Class<S!>!,
    interfaceType1: Class<Any!>!,
    otherInterfaces: Array<Class<Any!>!>!
)

Public functions

Unit
describeMismatch(item: Any!, mismatchDescription: Description!)

This method provides a default implementation for null check as well as a super type and interface checks provided by the constructor.

Unit
describeTo(description: Description!)
Boolean
matches(item: Any!)

Protected functions

abstract Unit
describeMoreTo(description: Description!)

Subclasses should implement this.

abstract Boolean
matchesSafely(item: T!, mismatchDescription: Description!)

Subclasses should implement this.

Inherited functions

From org.hamcrest.BaseMatcher

Public constructors

BoundedDiagnosingMatcher

BoundedDiagnosingMatcher(expectedType: Class<S!>!)

BoundedDiagnosingMatcher

BoundedDiagnosingMatcher(
    expectedType: Class<S!>!,
    interfaceType1: Class<Any!>!,
    otherInterfaces: Array<Class<Any!>!>!
)

Public functions

describeMismatch

fun describeMismatch(item: Any!, mismatchDescription: Description!): Unit

This method provides a default implementation for null check as well as a super type and interface checks provided by the constructor. Failing either check provides a default mismatch description. Passing both will call into matchesSafely which will allow the sub-class to check for a mismatch and describe what went wrong (if anything at all).

Parameters
item: Any!

The item which is assumed to have mismatched and should be described.

mismatchDescription: Description!

The description builder for the mismatch.

See also
TypeSafeDiagnosingMatcher

for similar implementation pattern.

describeTo

fun describeTo(description: Description!): Unit

matches

fun matches(item: Any!): Boolean

Protected functions

describeMoreTo

protected abstract fun describeMoreTo(description: Description!): Unit

Subclasses should implement this. The fine details of the matcher should be added to the description. Type checking information will have already been added.

Parameters
description: Description!

The Description object to write to.

matchesSafely

protected abstract fun matchesSafely(item: T!, mismatchDescription: Description!): Boolean

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

Parameters
item: T!

The pre-checked item.

mismatchDescription: Description!

A Description to write to for mismatches.

Returns
Boolean

true if the item matches the expectations for this Matcher.