Support suppressed exceptions in the TestContext framework

Prior to this commit, if multiple TestExecutionListener 'after' methods
threw an exception, only the first such exception was rethrown.
Subsequent exceptions were logged, but there was no way to access or
process them other than via the log file.

This commit addresses this shortcoming by making use of the support for
suppressed exceptions introduced in Java 7. Specifically, if multiple
TestExecutionListener 'after' methods throw an exception, the first
exception will be rethrown with subsequent exceptions suppressed in the
first one.

Issue: SPR-14459
This commit is contained in:
Sam Brannen
2016-07-13 20:29:01 +02:00
parent 5f176f50d3
commit 7ec85a3c3b
2 changed files with 149 additions and 0 deletions

View File

@@ -368,6 +368,9 @@ public class TestContextManager {
if (afterTestExecutionException == null) {
afterTestExecutionException = ex;
}
else {
afterTestExecutionException.addSuppressed(ex);
}
}
}
if (afterTestExecutionException != null) {
@@ -423,6 +426,9 @@ public class TestContextManager {
if (afterTestMethodException == null) {
afterTestMethodException = ex;
}
else {
afterTestMethodException.addSuppressed(ex);
}
}
}
if (afterTestMethodException != null) {
@@ -464,6 +470,9 @@ public class TestContextManager {
if (afterTestClassException == null) {
afterTestClassException = ex;
}
else {
afterTestClassException.addSuppressed(ex);
}
}
}
if (afterTestClassException != null) {