public class ThrowableMatcher<T>
extends org.hamcrest.BaseMatcher<T>
Matcher that can be used to match Throwables raised while
performing assertions instead of matching values.
Typically this class is used with the assertion methods provided by
the Eventually class.
For example:
Eventually.assertThat(invoking(object).someMethod(), willThrow(instanceOf(NullPointerException.class)));
Copyright (c) 2016. All Rights Reserved. Oracle Corporation.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
| Modifier and Type | Method and Description |
|---|---|
ThrowableMatcher<T> |
causedBy(org.hamcrest.Matcher<? super Throwable> matcher)
Obtains a new
ThrowableMatcher that includes matching a cause of the
Throwable. |
void |
describeTo(org.hamcrest.Description description) |
org.hamcrest.Matcher<? super Throwable> |
getMatcher()
Obtain the
Matcher for the Throwable. |
boolean |
matches(Object o) |
static <T> ThrowableMatcher<T> |
willThrow(Class<? extends Throwable> throwableClass)
Obtains a
ThrowableMatcher for the specified class of Throwable. |
static <T> ThrowableMatcher<T> |
willThrow(org.hamcrest.Matcher<? super Throwable> matcher)
|
ThrowableMatcher<T> |
withMessage(org.hamcrest.Matcher<? super String> matcher)
Obtains a new
ThrowableMatcher that includes the matching the
Throwable.getMessage() |
ThrowableMatcher<T> |
withMessage(String message)
Obtains a new
ThrowableMatcher that includes matching the specified
message. |
public static <T> ThrowableMatcher<T> willThrow(Class<? extends Throwable> throwableClass)
ThrowableMatcher for the specified class of Throwable.T - an expected type of valuethrowableClass - the class of ThrowableThrowableMatcherpublic static <T> ThrowableMatcher<T> willThrow(org.hamcrest.Matcher<? super Throwable> matcher)
T - an expected type of valuematcher - the Matcher for ThrowablesThrowableMatcherpublic ThrowableMatcher<T> withMessage(org.hamcrest.Matcher<? super String> matcher)
ThrowableMatcher that includes the matching the
Throwable.getMessage()matcher - the MatcherThrowableMatcherpublic ThrowableMatcher<T> withMessage(String message)
ThrowableMatcher that includes matching the specified
message.message - the message to matchThrowableMatcherpublic ThrowableMatcher<T> causedBy(org.hamcrest.Matcher<? super Throwable> matcher)
ThrowableMatcher that includes matching a cause of the
Throwable.matcher - the matched for the caused-by ThrowableThrowableMatcherpublic org.hamcrest.Matcher<? super Throwable> getMatcher()
Matcher for the Throwable.Throwable Matcherpublic boolean matches(Object o)
public void describeTo(org.hamcrest.Description description)
Copyright © 2017. All rights reserved.