Skip to content

Commit

Permalink
Merge pull request #5408 from kriegfrj/5402-NPE-on-notests
Browse files Browse the repository at this point in the history
[junit-platform] Handle null summary if no tests found
  • Loading branch information
kriegfrj authored Oct 23, 2022
2 parents 49f35bc + 51bd12e commit 2cc7ebc
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
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 2cc7ebc

Please sign in to comment.