Skip to content

Commit ca5f5ae

Browse files
committed
Fix FailureDetectingExternalResource to properly handle assumption failures
1 parent 7140578 commit ca5f5ae

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

modules/junit-vintage/src/main/java/org/testcontainers/junit/vintage/FailureDetectingExternalResource.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
/**
1313
* {@link TestRule} which is called before and after each test, and also is notified on success/failure.
1414
*
15-
* This mimics the behaviour of TestWatcher to some degree, but failures occurring in this rule do not
16-
* contribute to the overall failure count (which can otherwise cause strange negative test success
17-
* figures).
15+
* This mimics the behaviour of TestWatcher to some degree, but failures occurring in {@code starting()}
16+
* prevent the test from being run.
1817
*/
1918
class FailureDetectingExternalResource implements TestRule {
2019

@@ -28,12 +27,14 @@ public void evaluate() throws Throwable {
2827
try {
2928
starting(description);
3029
base.evaluate();
31-
succeeded(description);
30+
notifySucceeded(description, errors);
31+
} catch (org.junit.internal.AssumptionViolatedException e) {
32+
// Do nothing.
3233
} catch (Throwable e) {
3334
errors.add(e);
34-
failed(e, description);
35+
notifyFailed(e, description, errors);
3536
} finally {
36-
finished(description, errors);
37+
notifyFinished(description, errors);
3738
}
3839

3940
MultipleFailureException.assertEmpty(errors);
@@ -49,6 +50,30 @@ protected void failed(Throwable e, Description description) {}
4950

5051
protected void finished(Description description, List<Throwable> errors) {}
5152

53+
private void notifySucceeded(Description description, List<Throwable> errors) {
54+
try {
55+
succeeded(description);
56+
} catch (Throwable e) {
57+
errors.add(e);
58+
}
59+
}
60+
61+
private void notifyFailed(Throwable failure, Description description, List<Throwable> errors) {
62+
try {
63+
failed(failure, description);
64+
} catch (Throwable e) {
65+
errors.add(e);
66+
}
67+
}
68+
69+
private void notifyFinished(Description description, List<Throwable> errors) {
70+
try {
71+
finished(description, errors);
72+
} catch (Throwable e) {
73+
errors.add(e);
74+
}
75+
}
76+
5277
protected static final TestDescription toTestDescription(Description description) {
5378
return new TestDescription() {
5479
@Override

0 commit comments

Comments
 (0)