From 2f2e6dffb4f66bfb6531b1f62caf784528020918 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 9 Sep 2016 18:02:47 +0200 Subject: [PATCH] Upgrade to TestNG 6.9.12 --- build.gradle | 2 +- .../AbstractTestNGSpringContextTests.java | 18 ++++++++++++++++-- .../ClassLevelDirtiesContextTestNGTests.java | 3 ++- ...ailingBeforeAndAfterMethodsTestNGTests.java | 3 ++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 6add490350..0076827b4a 100644 --- a/build.gradle +++ b/build.gradle @@ -86,7 +86,7 @@ configure(allprojects) { project -> ext.slf4jVersion = "1.7.21" ext.snakeyamlVersion = "1.17" ext.snifferVersion = "1.15" - ext.testngVersion = "6.9.10" + ext.testngVersion = "6.9.12" ext.tiles3Version = "3.0.5" ext.tomcatVersion = "8.5.4" ext.tyrusVersion = "1.13" diff --git a/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTestNGSpringContextTests.java b/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTestNGSpringContextTests.java index fcffa7f3fc..c36c4e4ca9 100644 --- a/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTestNGSpringContextTests.java +++ b/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTestNGSpringContextTests.java @@ -178,7 +178,6 @@ public abstract class AbstractTestNGSpringContextTests implements IHookable, App beforeCallbacksExecuted = true; } catch (Throwable ex) { - testResult.setThrowable(ex); this.testException = ex; } @@ -192,10 +191,13 @@ public abstract class AbstractTestNGSpringContextTests implements IHookable, App } catch (Throwable ex) { if (this.testException == null) { - testResult.setThrowable(ex); this.testException = ex; } } + + if (this.testException != null) { + throwAsUncheckedException(this.testException); + } } /** @@ -237,4 +239,16 @@ public abstract class AbstractTestNGSpringContextTests implements IHookable, App return testResultException; } + private RuntimeException throwAsUncheckedException(Throwable t) { + throwAs(t); + + // Appeasing the compiler: the following line will never be executed. + return null; + } + + @SuppressWarnings("unchecked") + private void throwAs(Throwable t) throws T { + throw (T) t; + } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java index 1c603e3399..85a4e7dbcc 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java @@ -36,6 +36,7 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.springframework.test.context.testng.TrackingTestNGTestListener; +import org.testng.ITestNGListener; import org.testng.TestNG; import static org.junit.Assert.*; @@ -142,7 +143,7 @@ public class ClassLevelDirtiesContextTestNGTests { final TrackingTestNGTestListener listener = new TrackingTestNGTestListener(); final TestNG testNG = new TestNG(); - testNG.addListener(listener); + testNG.addListener((ITestNGListener) listener); testNG.setTestClasses(new Class[] { testClass }); testNG.setVerbose(0); testNG.run(); diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/FailingBeforeAndAfterMethodsTestNGTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/FailingBeforeAndAfterMethodsTestNGTests.java index 8a28865763..15ed4112d8 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/FailingBeforeAndAfterMethodsTestNGTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/FailingBeforeAndAfterMethodsTestNGTests.java @@ -32,6 +32,7 @@ import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.util.ClassUtils; +import org.testng.ITestNGListener; import org.testng.TestNG; import static org.junit.Assert.*; @@ -90,7 +91,7 @@ public class FailingBeforeAndAfterMethodsTestNGTests { public void runTestAndAssertCounters() throws Exception { final TrackingTestNGTestListener listener = new TrackingTestNGTestListener(); final TestNG testNG = new TestNG(); - testNG.addListener(listener); + testNG.addListener((ITestNGListener) listener); testNG.setTestClasses(new Class[] { this.clazz }); testNG.setVerbose(0); testNG.run();