Skip to content
Browse files

Throw MulitpleFailureException

  • Loading branch information...
1 parent c228881 commit c07b3e7ea1b23d84590c2781b978f15e40c94703 @davidhart82 davidhart82 committed
Showing with 29 additions and 0 deletions.
  1. +29 −0 src/test/java/org/junit/tests/experimental/rules/TestWatcherTest.java
View
29 src/test/java/org/junit/tests/experimental/rules/TestWatcherTest.java
@@ -4,10 +4,15 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeTrue;
+import static org.junit.experimental.results.PrintableResult.testResult;
+import static org.junit.experimental.results.ResultMatchers.*;
import static org.junit.runner.JUnitCore.runClasses;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.experimental.results.PrintableResult;
import org.junit.rules.TestRule;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
public class TestWatcherTest {
public static class ViolatedAssumptionTest {
@@ -49,4 +54,28 @@ public void logFailingTest() {
assertThat(FailingTest.watchedLog.toString(),
is("starting failed finished "));
}
+
+ public static class TestWatcherThrowsExceptionTest {
+ @Rule
+ public TestRule watcher= new TestWatcher() {
+ @Override
+ protected void failed(Throwable e, Description description) {
+ throw new RuntimeException("watcher failure");
+ }
+ };
+
+ @Test
+ public void fails() {
+ throw new IllegalArgumentException("test failure");
+ }
+ }
+
+ @Test
+ public void testWatcherThrowsException() {
+ PrintableResult result= testResult(TestWatcherThrowsExceptionTest.class);
+ assertThat(result, failureCountIs(2));
+ assertThat(result, hasFailureContaining("test failure"));
+ assertThat(result, hasFailureContaining("watcher failure"));
+
+ }
}

0 comments on commit c07b3e7

Please sign in to comment.
Something went wrong with that request. Please try again.