1717import org .testng .TestNGException ;
1818import org .testng .annotations .IListenersAnnotation ;
1919import org .testng .internal .annotations .IAnnotationFinder ;
20+ import org .testng .util .Invocable ;
2021
2122/** A helper class that internally houses some of the listener related actions support. */
2223public final class TestListenerHelper {
@@ -34,12 +35,8 @@ public static void runPreConfigurationListeners(
3435 List <IConfigurationListener > original = ListenerOrderDeterminer .order (listeners , comparator );
3536
3637 for (IConfigurationListener icl : original ) {
37- icl .beforeConfiguration (tr );
38- try {
39- icl .beforeConfiguration (tr , tm );
40- } catch (Exception e ) {
41- ignoreInternalGradleException (e );
42- }
38+ Invocable .runQuietly (() -> icl .beforeConfiguration (tr ));
39+ Invocable .runQuietly (() -> icl .beforeConfiguration (tr , tm ));
4340 }
4441 }
4542
@@ -55,44 +52,23 @@ public static void runPostConfigurationListeners(
5552 for (IConfigurationListener icl : listenersreversed ) {
5653 switch (tr .getStatus ()) {
5754 case ITestResult .SKIP :
58- icl .onConfigurationSkip (tr );
59- try {
60- icl .onConfigurationSkip (tr , tm );
61- } catch (Exception e ) {
62- ignoreInternalGradleException (e );
63- }
55+ Invocable .runQuietly (() -> icl .onConfigurationSkip (tr ));
56+ Invocable .runQuietly (() -> icl .onConfigurationSkip (tr , tm ));
6457 break ;
6558 case ITestResult .FAILURE :
66- icl .onConfigurationFailure (tr );
67- try {
68- icl .onConfigurationFailure (tr , tm );
69- } catch (Exception e ) {
70- ignoreInternalGradleException (e );
71- }
59+ Invocable .runQuietly (() -> icl .onConfigurationFailure (tr ));
60+ Invocable .runQuietly (() -> icl .onConfigurationFailure (tr , tm ));
7261 break ;
7362 case ITestResult .SUCCESS :
74- icl .onConfigurationSuccess (tr );
75- try {
76- icl .onConfigurationSuccess (tr , tm );
77- } catch (Exception e ) {
78- ignoreInternalGradleException (e );
79- }
63+ Invocable .runQuietly (() -> icl .onConfigurationSuccess (tr ));
64+ Invocable .runQuietly (() -> icl .onConfigurationSuccess (tr , tm ));
8065 break ;
8166 default :
8267 throw new AssertionError ("Unexpected value: " + tr .getStatus ());
8368 }
8469 }
8570 }
8671
87- // This method is added because Gradle which builds TestNG seems to be using an older version
88- // of TestNG that doesn't know about the new methods that we added and so it causes
89- // the TestNG build to keep failing.
90- private static void ignoreInternalGradleException (Exception e ) {
91- if (!e .getClass ().getPackage ().getName ().startsWith ("org.gradle.internal" )) {
92- throw new ListenerInvocationException (e );
93- }
94- }
95-
9672 /**
9773 * Iterates through a bunch of listeners and invokes them.
9874 *
@@ -103,23 +79,23 @@ public static void runTestListeners(ITestResult tr, List<ITestListener> listener
10379 for (ITestListener itl : listeners ) {
10480 switch (tr .getStatus ()) {
10581 case ITestResult .SKIP :
106- itl .onTestSkipped (tr );
82+ Invocable . runQuietly (() -> itl .onTestSkipped (tr ) );
10783 break ;
10884 case ITestResult .SUCCESS_PERCENTAGE_FAILURE :
109- itl .onTestFailedButWithinSuccessPercentage (tr );
85+ Invocable . runQuietly (() -> itl .onTestFailedButWithinSuccessPercentage (tr ) );
11086 break ;
11187 case ITestResult .FAILURE :
11288 if (ITestResult .wasFailureDueToTimeout (tr )) {
113- itl .onTestFailedWithTimeout (tr );
89+ Invocable . runQuietly (() -> itl .onTestFailedWithTimeout (tr ) );
11490 } else {
115- itl .onTestFailure (tr );
91+ Invocable . runQuietly (() -> itl .onTestFailure (tr ) );
11692 }
11793 break ;
11894 case ITestResult .SUCCESS :
119- itl .onTestSuccess (tr );
95+ Invocable . runQuietly (() -> itl .onTestSuccess (tr ) );
12096 break ;
12197 case ITestResult .STARTED :
122- itl .onTestStart (tr );
98+ Invocable . runQuietly (() -> itl .onTestStart (tr ) );
12399 break ;
124100 default :
125101 throw new AssertionError ("Unknown status: " + tr .getStatus ());
0 commit comments