Skip to content

Commit

Permalink
Throw MulitpleFailureException
Browse files Browse the repository at this point in the history
  • Loading branch information
djh82 committed Jun 24, 2012
1 parent c07b3e7 commit 8c1c0e7
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions 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;

/**
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -91,4 +105,4 @@ protected void starting(Description description) {
*/
protected void finished(Description description) {
}
}
}

0 comments on commit 8c1c0e7

Please sign in to comment.