Skip to content
This repository was archived by the owner on Sep 3, 2020. It is now read-only.

Commit 1ac4073

Browse files
committed
Add ExceptionWrapper test rule
1 parent 54e75a8 commit 1ac4073

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package scala.tools.refactoring.tests.util;
2+
3+
import org.junit.rules.TestRule;
4+
import org.junit.runner.Description;
5+
import org.junit.runners.model.Statement;
6+
7+
import scala.tools.nsc.util.FailedInterrupt;
8+
9+
/**
10+
* In case an assertion error is caught and wrapped by another error type (as it
11+
* is the case for exceptions that are thrown on the compiler thread), we need
12+
* to manually unwrap them later, in order to let JUnit "see" them.
13+
*/
14+
public final class ExceptionWrapper implements TestRule {
15+
16+
@Override
17+
public Statement apply(final Statement base, final Description description) {
18+
return new Statement() {
19+
@Override
20+
public void evaluate() throws Throwable {
21+
try {
22+
base.evaluate();
23+
} catch (FailedInterrupt e) {
24+
// a FailedInterrupt is thrown when an exception occurs on the compiler thread
25+
throw e.getCause();
26+
}
27+
}
28+
};
29+
}
30+
}

org.scala-refactoring.library/src/test/java/scala/tools/refactoring/tests/util/TestRules.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ public abstract class TestRules {
88

99
@Rule
1010
public final ScalaVersionTestRule rule1 = new ScalaVersionTestRule();
11+
12+
@Rule
13+
public final ExceptionWrapper rule2 = new ExceptionWrapper();
1114
}

0 commit comments

Comments
 (0)