@@ -49,6 +49,8 @@ public class ConsoleTestExecutor {
4949 private final TestConsoleOutputOptions outputOptions ;
5050 private final Supplier <Launcher > launcherSupplier ;
5151
52+ private TestPlan testPlanListeners ;
53+
5254 public ConsoleTestExecutor (TestDiscoveryOptions discoveryOptions , TestConsoleOutputOptions outputOptions ) {
5355 this (discoveryOptions , outputOptions , LauncherFactory ::create );
5456 }
@@ -99,11 +101,12 @@ private TestExecutionSummary executeTests(PrintWriter out, Optional<Path> report
99101 Launcher launcher = launcherSupplier .get ();
100102 SummaryGeneratingListener summaryListener = registerListeners (out , reportsDir , launcher );
101103 LauncherDiscoveryRequest discoveryRequest = new DiscoveryRequestCreator ().toDiscoveryRequest (discoveryOptions );
102- TestPlanCapturer testPlanCapturer = new TestPlanCapturer ();
103104 launcher .execute (discoveryRequest );
104105 TestExecutionSummary summary = summaryListener .getSummary ();
105106 if (summary .getTotalFailureCount () > 0 || outputOptions .getDetails () != Details .NONE ) {
106- printSummary (summary , testPlanCapturer .testPlan , out );
107+ //get testPlan from summaryListener
108+ testPlanListeners = summaryListener .getTestPlan ();
109+ printSummary (summary , out );
107110 }
108111
109112 return summary ;
@@ -177,7 +180,7 @@ private Optional<TestExecutionListener> createXmlWritingListener(PrintWriter out
177180 return reportsDir .map (it -> new LegacyXmlReportGeneratingListener (it , out ));
178181 }
179182
180- private void printSummary (TestExecutionSummary summary , TestPlan testPlan , PrintWriter out ) {
183+ private void printSummary (TestExecutionSummary summary , PrintWriter out ) {
181184 // Otherwise the failures have already been printed in detail
182185 if (EnumSet .of (Details .NONE , Details .SUMMARY , Details .TREE ).contains (outputOptions .getDetails ())) {
183186 summary .printFailuresTo (out );
@@ -195,7 +198,7 @@ private void printSummary(TestExecutionSummary summary, TestPlan testPlan, Print
195198 ValueWrapper actual = assertionFailedError .getActual ();
196199 //apply diff function
197200 if (isCharSequence (expected ) && isCharSequence (actual )) {
198- new DiffPrinter (testPlan ).printDiff (out , expected .getStringRepresentation (),
201+ new DiffPrinter (testPlanListeners ).printDiff (out , expected .getStringRepresentation (),
199202 actual .getStringRepresentation (), failure .getTestIdentifier ());
200203 }
201204 }
@@ -212,14 +215,4 @@ private boolean isCharSequence(ValueWrapper value) {
212215 public interface Factory {
213216 ConsoleTestExecutor create (TestDiscoveryOptions discoveryOptions , TestConsoleOutputOptions outputOptions );
214217 }
215-
216- private static class TestPlanCapturer implements TestExecutionListener {
217-
218- private TestPlan testPlan ;
219-
220- @ Override
221- public void testPlanExecutionStarted (TestPlan testPlan ) {
222- this .testPlan = testPlan ;
223- }
224- }
225218}
0 commit comments