Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Throw MulitpleFailureException

  • Loading branch information...
commit 8c1c0e7ee79860a603b68d8a9335ce0bce966160 1 parent c07b3e7
@davidhart82 davidhart82 authored
Showing with 23 additions and 9 deletions.
  1. +23 −9 src/main/java/org/junit/rules/TestWatcher.java
View
32 src/main/java/org/junit/rules/TestWatcher.java
@@ -1,7 +1,11 @@
package org.junit.rules;
+import java.util.ArrayList;
+import java.util.List;
+
import org.junit.internal.AssumptionViolatedException;
import org.junit.runner.Description;
+import org.junit.runners.model.MultipleFailureException;
import org.junit.runners.model.Statement;
/**
@@ -36,28 +40,38 @@
* }
* }
* </pre>
+ * @since 4.9
*/
public abstract class TestWatcher implements TestRule {
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
- starting(description);
+ List<Throwable> errors = new ArrayList<Throwable>();
try {
- base.evaluate();
- succeeded(description);
+ starting(description);
+ try {
+ base.evaluate();
+ succeeded(description);
+ } catch (AssumptionViolatedException e) {
+ throw e;
+ } catch (Throwable t) {
+ errors.add(t);
+ failed(t, description);
+ } finally {
+ finished(description);
+ }
} catch (AssumptionViolatedException e) {
throw e;
} catch (Throwable t) {
- failed(t, description);
- throw t;
- } finally {
- finished(description);
+ errors.add(t);
}
+ if (!errors.isEmpty())
+ throw new MultipleFailureException(errors);
}
};
}
-
+
/**
* Invoked when a test succeeds
*
@@ -91,4 +105,4 @@ protected void starting(Description description) {
*/
protected void finished(Description description) {
}
-}
+}

0 comments on commit 8c1c0e7

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