{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
public abstract class BoundedDiagnosingMatcher<S, T extends S> extends BaseMatcher
| java.lang.Object | ||
| ↳ | org.hamcrest.BaseMatcher | |
| ↳ | androidx.test.espresso.matcher.BoundedDiagnosingMatcher | |
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 extends S> |
The actual type that the matcher applies safely to. |
Public constructors |
|
|---|---|
BoundedDiagnosingMatcher(Class<S> expectedType) |
|
BoundedDiagnosingMatcher( |
|
Public methods |
|
|---|---|
final void |
describeMismatch(Object item, Description mismatchDescription)This method provides a default implementation for |
final void |
describeTo(Description description) |
final boolean |
|
Protected methods |
|
|---|---|
abstract void |
describeMoreTo(Description description)Subclasses should implement this. |
abstract boolean |
matchesSafely(T item, Description mismatchDescription)Subclasses should implement this. |
public BoundedDiagnosingMatcher(
Class<S> expectedType,
Class<Object> interfaceType1,
Class[] otherInterfaces
)
public final void describeMismatch(Object item, Description mismatchDescription)
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 | |
|---|---|
Object item |
The item which is assumed to have mismatched and should be described. |
Description mismatchDescription |
The description builder for the mismatch. |
| See also | |
|---|---|
TypeSafeDiagnosingMatcher |
for similar implementation pattern. |
protected abstract void describeMoreTo(Description description)
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 |
protected abstract boolean matchesSafely(T item, Description mismatchDescription)
Subclasses should implement this. The item will already have been checked for the specific type, interfaces, and will never be null.
| Parameters | |
|---|---|
T item |
The pre-checked item. |
Description mismatchDescription |
A |
| Returns | |
|---|---|
boolean |
|