diff options
Diffstat (limited to 'src/main/java/org/junit/internal/matchers/ThrowableCauseMatcher.java')
-rw-r--r-- | src/main/java/org/junit/internal/matchers/ThrowableCauseMatcher.java | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/src/main/java/org/junit/internal/matchers/ThrowableCauseMatcher.java b/src/main/java/org/junit/internal/matchers/ThrowableCauseMatcher.java deleted file mode 100644 index 22ce8bd..0000000 --- a/src/main/java/org/junit/internal/matchers/ThrowableCauseMatcher.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.junit.internal.matchers; - -import org.hamcrest.Description; -import org.hamcrest.Factory; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; - -/** - * A matcher that applies a delegate matcher to the cause of the current Throwable, returning the result of that - * match. - * - * @param <T> the type of the throwable being matched - */ -public class ThrowableCauseMatcher<T extends Throwable> extends - TypeSafeMatcher<T> { - - private final Matcher<? extends Throwable> causeMatcher; - - public ThrowableCauseMatcher(Matcher<? extends Throwable> causeMatcher) { - this.causeMatcher = causeMatcher; - } - - public void describeTo(Description description) { - description.appendText("exception with cause "); - description.appendDescriptionOf(causeMatcher); - } - - @Override - protected boolean matchesSafely(T item) { - return causeMatcher.matches(item.getCause()); - } - - @Override - protected void describeMismatchSafely(T item, Description description) { - description.appendText("cause "); - causeMatcher.describeMismatch(item.getCause(), description); - } - - /** - * 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<? extends Throwable> matcher) { - return new ThrowableCauseMatcher<T>(matcher); - } -}
\ No newline at end of file |