T - the expected throwable typepublic final class ThrowsException<T extends Throwable> extends org.hamcrest.TypeSafeMatcher<Block>
HasCause,
HasMessage,
Block| Modifier and Type | Method and Description |
|---|---|
void |
describeTo(org.hamcrest.Description description) |
protected boolean |
matchesSafely(Block block) |
static <T extends Throwable> |
throwsException(Class<T> expectedExceptionClass)
Creates a matcher that matches if the examined
Block throws an exception
of the specified expectedExceptionClass. |
static <T extends Throwable> |
throwsException(Class<T> expectedExceptionClass,
org.hamcrest.Matcher<T> exceptionMatcher)
Creates a matcher that matches if the examined
Block throws an exception
of the specified expectedExceptionClass and is matched by the specified
exceptionMatcher. |
static <T extends Throwable> |
throwsException(Class<T> expectedExceptionClass,
org.hamcrest.Matcher<T> exceptionMatcher,
org.hamcrest.Matcher<T>... additionalExceptionMatchers)
Creates a matcher that matches if the examined
Block throws an exception
of the specified expectedExceptionClass and is matched by the specified
exceptionMatcher and additionalExceptionMatchers. |
describeMismatch, describeMismatchSafely, matchespublic static <T extends Throwable> org.hamcrest.Matcher<Block> throwsException(Class<T> expectedExceptionClass)
Block throws an exception
of the specified expectedExceptionClass.
For example:
assertThat(() -> Long.parseLong("foo"), throwsException(NumberFormatException.class));T - the expected throwable typeexpectedExceptionClass - the expected exception typepublic static <T extends Throwable> org.hamcrest.TypeSafeMatcher<Block> throwsException(Class<T> expectedExceptionClass, org.hamcrest.Matcher<T> exceptionMatcher)
Block throws an exception
of the specified expectedExceptionClass and is matched by the specified
exceptionMatcher.
For example:
assertThat(() -> Long.parseLong("foo"), throwsException(NumberFormatException.class, hasMessage("For input string: \"foo\"")));T - the expected throwable typeexpectedExceptionClass - the expected exception typeexceptionMatcher - the matcher to apply to the examined exception@SafeVarargs public static <T extends Throwable> org.hamcrest.TypeSafeMatcher<Block> throwsException(Class<T> expectedExceptionClass, org.hamcrest.Matcher<T> exceptionMatcher, org.hamcrest.Matcher<T>... additionalExceptionMatchers)
Block throws an exception
of the specified expectedExceptionClass and is matched by the specified
exceptionMatcher and additionalExceptionMatchers.
For example:
assertThat(() -> Long.parseLong("foo"), throwsException(NumberFormatException.class, hasMessage("For input string: \"foo\""), hasCause(nullValue())));T - the expected throwable typeexpectedExceptionClass - the expected exception typeexceptionMatcher - the matcher to apply to the examined exceptionadditionalExceptionMatchers - additional matchers to apply to the examined exceptionpublic void describeTo(org.hamcrest.Description description)
Copyright © 2013–2015. All rights reserved.