/** * @return A matcher that delegates to exceptionMatcher and in addition * appends the stacktrace of the actual Exception in case of a mismatch. */ public static <T extends Exception> Matcher<T> isException(Matcher<T> exceptionMatcher) { return StacktracePrintingMatcher.isException(exceptionMatcher); } }
/** * @return A matcher that delegates to throwableMatcher and in addition * appends the stacktrace of the actual Throwable in case of a mismatch. */ public static <T extends Throwable> Matcher<T> isThrowable(Matcher<T> throwableMatcher) { return StacktracePrintingMatcher.isThrowable(throwableMatcher); }
@Factory public static <T extends Throwable> Matcher<T> isThrowable( Matcher<T> throwableMatcher) { return new StacktracePrintingMatcher<T>(throwableMatcher); }
/** * Adds {@code matcher} to the list of requirements for the message returned * from any thrown exception. */ public void expectMessage(Matcher<String> matcher) { expect(hasMessage(matcher)); }
/** * Adds {@code matcher} to the list of requirements for the cause of * any thrown exception. */ public void expectCause(Matcher<? extends Throwable> expectedCause) { expect(hasCause(expectedCause)); }
@Factory public static <T extends Throwable> Matcher<T> hasMessage(final Matcher<String> matcher) { return new ThrowableMessageMatcher<T>(matcher); } }
/** * Returns a matcher that verifies that the outer exception has a cause for which the supplied matcher * evaluates to true. * * @param matcher to apply to the cause of the outer exception * @param <T> type of the outer exception */ @Factory public static <T extends Throwable> Matcher<T> hasCause(final Matcher<?> matcher) { return new ThrowableCauseMatcher<T>(matcher); } }
/** * Method made final to prevent accidental override. * If you need to override this, there's no point on extending TypeSafeMatcher. * Instead, extend the {@link BaseMatcher}. */ @SuppressWarnings({"unchecked"}) public final boolean matches(Object item) { return item != null && expectedType.isInstance(item) && matchesSafely((T) item); } }
protected TypeSafeMatcher() { expectedType = findExpectedType(getClass()); }
@Override protected void describeMismatchSafely(T item, Description description) { throwableMatcher.describeMismatch(item, description); description.appendText("\nStacktrace was: "); description.appendText(readStacktrace(item)); }
@Factory public static <T extends Exception> Matcher<T> isException( Matcher<T> exceptionMatcher) { return new StacktracePrintingMatcher<T>(exceptionMatcher); } }
@Factory public static <T extends Throwable> Matcher<T> hasMessage(final Matcher<String> matcher) { return new ThrowableMessageMatcher<T>(matcher); } }
@Factory public static <T extends Throwable> Matcher<T> hasCause(final Matcher<T> matcher) { return new ThrowableCauseMatcher<T>(matcher); } }
/** * @return A matcher that delegates to exceptionMatcher and in addition * appends the stacktrace of the actual Exception in case of a mismatch. */ public static <T extends Exception> Matcher<T> isException(Matcher<T> exceptionMatcher) { return StacktracePrintingMatcher.isException(exceptionMatcher); } }
/** * @return A matcher that delegates to throwableMatcher and in addition * appends the stacktrace of the actual Throwable in case of a mismatch. */ public static <T extends Throwable> Matcher<T> isThrowable(Matcher<T> throwableMatcher) { return StacktracePrintingMatcher.isThrowable(throwableMatcher); }
/** * Method made final to prevent accidental override. * If you need to override this, there's no point on extending TypeSafeMatcher. * Instead, extend the {@link BaseMatcher}. */ @SuppressWarnings({"unchecked"}) public final boolean matches(Object item) { return item != null && expectedType.isInstance(item) && matchesSafely((T) item); } }
protected TypeSafeMatcher() { expectedType = findExpectedType(getClass()); }
@Override protected void describeMismatchSafely(T item, Description description) { fThrowableMatcher.describeMismatch(item, description); description.appendText("\nStacktrace was: "); description.appendText(readStacktrace(item)); }
@Factory public static <T extends Throwable> Matcher<T> isThrowable( Matcher<T> throwableMatcher) { return new StacktracePrintingMatcher<T>(throwableMatcher); }
@Factory public static <T extends Exception> Matcher<T> isException( Matcher<T> exceptionMatcher) { return new StacktracePrintingMatcher<T>(exceptionMatcher); } }