Skip to content

Commit

Permalink
[junit-platform] Handle null summary if no tests found
Browse files Browse the repository at this point in the history
Fixes #5402

Signed-off-by: Fr Jeremy Krieg <fr.jkrieg@greekwelfaresa.org.au>
  • Loading branch information
kriegfrj committed Oct 23, 2022
1 parent 49f35bc commit 51bd12e
Showing 1 changed file with 13 additions and 8 deletions.
Expand Up @@ -49,6 +49,7 @@
import org.junit.platform.launcher.core.LauncherFactory;
import org.junit.platform.launcher.listeners.LoggingListener;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
import org.junit.platform.launcher.listeners.TestExecutionSummary;
import org.osgi.annotation.bundle.Header;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
Expand Down Expand Up @@ -432,6 +433,7 @@ long test(LauncherDiscoveryRequest testRequest) {
ServiceTracker<TestExecutionListener, TestExecutionListener> track = new ServiceTracker<>(context,
TestExecutionListener.class, null);
track.open();
final TestExecutionSummary execSummary;
try {
TestExecutionListener[] listenerArray = Stream
.concat(listeners.stream(), Arrays.stream(track.getServices(new TestExecutionListener[0])))
Expand All @@ -440,17 +442,20 @@ long test(LauncherDiscoveryRequest testRequest) {
} catch (Throwable t) {
trace("%s", t);
} finally {
execSummary = summary.getSummary();
track.close();
trace(null, () -> {
CharArrayWriter sw = new CharArrayWriter();
summary.getSummary()
.printTo(new PrintWriter(sw));
return sw.toString();
});
if (execSummary != null) {
trace(null, () -> {
CharArrayWriter sw = new CharArrayWriter();
execSummary.printTo(new PrintWriter(sw));
return sw.toString();
});
} else {
trace("No summary available");
}
}

return summary.getSummary()
.getTotalFailureCount();
return (execSummary != null) ? execSummary.getTotalFailureCount() : -1;
} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 51bd12e

Please sign in to comment.