public class ThrowableMatcher extends ResultProvidingMatcher<java.lang.Throwable>
Class implements a Matcher that checks type of an exception. If specified expected type is null
then matcher will expect null instead of actual throwable value.
Difference from Matchers.instanceOf(Class) and Matchers.nullValue() is that this matcher
sets asserted throwable as cause of the result.
Also matcher produces more obvious (exception related) messages.
throwableOfType(Class),
notExpected()| Modifier and Type | Method and Description |
|---|---|
void |
describeTo(org.hamcrest.Description description) |
java.lang.Class<? extends java.lang.Throwable> |
getExpectedType() |
java.util.Optional<AssertResult> |
matches(java.lang.Throwable item,
java.lang.String message,
java.lang.Throwable cause)
This method should return
Optional.empty() in case matcher successfully matched specified item. |
static ThrowableMatcher |
notExpected()
Creates an instance of
ThrowableMatcher with null as expected type. |
static ThrowableMatcher |
throwableOfType(java.lang.Class<? extends java.lang.Throwable> type)
Creates an instance of
ThrowableMatcher with specified type, as expected. |
matchespublic java.lang.Class<? extends java.lang.Throwable> getExpectedType()
public java.util.Optional<AssertResult> matches(java.lang.Throwable item, java.lang.String message, java.lang.Throwable cause)
ResultProvidingMatcherOptional.empty() in case matcher successfully matched specified item.
Otherwise it should return an optional containing an instance of the AssertResult.matches in class ResultProvidingMatcher<java.lang.Throwable>public void describeTo(org.hamcrest.Description description)
public static ThrowableMatcher throwableOfType(java.lang.Class<? extends java.lang.Throwable> type)
ThrowableMatcher with specified type, as expected.notExpected()public static ThrowableMatcher notExpected()
ThrowableMatcher with null as expected type.throwableOfType(Class)