Skip to content

Commit eef975b

Browse files
committed
Combine PR made by Marc from #1
add testPlanCapturer listener
1 parent f44f929 commit eef975b

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

junit-platform-console/src/main/java/org/junit/platform/console/tasks/ConsoleTestExecutor.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public class ConsoleTestExecutor {
4949
private final TestConsoleOutputOptions outputOptions;
5050
private final Supplier<Launcher> launcherSupplier;
5151

52-
private TestPlan testPlanListeners;
53-
5452
public ConsoleTestExecutor(TestDiscoveryOptions discoveryOptions, TestConsoleOutputOptions outputOptions) {
5553
this(discoveryOptions, outputOptions, LauncherFactory::create);
5654
}
@@ -101,12 +99,11 @@ private TestExecutionSummary executeTests(PrintWriter out, Optional<Path> report
10199
Launcher launcher = launcherSupplier.get();
102100
SummaryGeneratingListener summaryListener = registerListeners(out, reportsDir, launcher);
103101
LauncherDiscoveryRequest discoveryRequest = new DiscoveryRequestCreator().toDiscoveryRequest(discoveryOptions);
102+
TestPlanCapturer testPlanCapturer = new TestPlanCapturer();
104103
launcher.execute(discoveryRequest);
105104
TestExecutionSummary summary = summaryListener.getSummary();
106105
if (summary.getTotalFailureCount() > 0 || outputOptions.getDetails() != Details.NONE) {
107-
//get testPlan from summaryListener
108-
testPlanListeners = summaryListener.getTestPlan();
109-
printSummary(summary, out);
106+
printSummary(summary, testPlanCapturer.testPlan, out);
110107
}
111108

112109
return summary;
@@ -180,7 +177,7 @@ private Optional<TestExecutionListener> createXmlWritingListener(PrintWriter out
180177
return reportsDir.map(it -> new LegacyXmlReportGeneratingListener(it, out));
181178
}
182179

183-
private void printSummary(TestExecutionSummary summary, PrintWriter out) {
180+
private void printSummary(TestExecutionSummary summary, TestPlan testPlan, PrintWriter out) {
184181
// Otherwise the failures have already been printed in detail
185182
if (EnumSet.of(Details.NONE, Details.SUMMARY, Details.TREE).contains(outputOptions.getDetails())) {
186183
summary.printFailuresTo(out);
@@ -198,7 +195,7 @@ private void printSummary(TestExecutionSummary summary, PrintWriter out) {
198195
ValueWrapper actual = assertionFailedError.getActual();
199196
//apply diff function
200197
if (isCharSequence(expected) && isCharSequence(actual)) {
201-
new DiffPrinter(testPlanListeners).printDiff(out, expected.getStringRepresentation(),
198+
new DiffPrinter(testPlan).printDiff(out, expected.getStringRepresentation(),
202199
actual.getStringRepresentation(), failure.getTestIdentifier());
203200
}
204201
}
@@ -215,4 +212,14 @@ private boolean isCharSequence(ValueWrapper value) {
215212
public interface Factory {
216213
ConsoleTestExecutor create(TestDiscoveryOptions discoveryOptions, TestConsoleOutputOptions outputOptions);
217214
}
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+
}
218225
}

junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/SummaryGeneratingListener.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ public TestExecutionSummary getSummary() {
4646
return this.summary;
4747
}
4848

49-
/**
50-
* Get the testPlan of this listener.
51-
*/
52-
public TestPlan getTestPlan() {
53-
return testPlan;
54-
}
55-
5649
@Override
5750
public void testPlanExecutionStarted(TestPlan testPlan) {
5851
this.testPlan = testPlan;

0 commit comments

Comments
 (0)