Skip to content

Commit

Permalink
Avoid NullPointerExceptions in console output in tests
Browse files Browse the repository at this point in the history
Prior to this commit, the following types of NullPointerExceptions were
overlooked in the console output.

java.lang.NullPointerException: Cannot invoke "org.junit.platform.console.tasks.ConsoleTestExecutor.execute(java.io.PrintWriter, java.util.Optional)" because the return value of "org.junit.platform.console.tasks.ConsoleTestExecutor$Factory.create(org.junit.platform.console.options.TestDiscoveryOptions, org.junit.platform.console.options.TestConsoleOutputOptions)" is null

Although the NullPointerExceptions did not cause the tests to fail,
this commit updates the tests to avoid them anyway.
  • Loading branch information
sbrannen committed Aug 17, 2023
1 parent 4eca30b commit bc862e0
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ class ConsoleLauncherTests {
@ParameterizedTest(name = "{0}")
@MethodSource("commandsWithEmptyOptionExitCodes")
void displayHelp(String command) {
var consoleLauncher = new ConsoleLauncher((__, ___) -> null, printSink, printSink);
var consoleLauncher = new ConsoleLauncher(ConsoleTestExecutor::new, printSink, printSink);
var exitCode = consoleLauncher.run(command, "--help").getExitCode();

assertEquals(0, exitCode);
assertThat(stringWriter.toString()).contains("--help");
assertThat(stringWriter.toString()).contains("--help", "--disable-banner", "--scan-classpath" /* ... */);
}

@ParameterizedTest(name = "{0}")
@MethodSource("commandsWithEmptyOptionExitCodes")
void displayBanner(String command) {
var consoleLauncher = new ConsoleLauncher((__, ___) -> null, printSink, printSink);
var consoleLauncher = new ConsoleLauncher(ConsoleTestExecutor::new, printSink, printSink);
consoleLauncher.run(command);

assertThat(stringWriter.toString()).contains(
Expand All @@ -54,7 +54,7 @@ void displayBanner(String command) {
@ParameterizedTest(name = "{0}")
@MethodSource("commandsWithEmptyOptionExitCodes")
void disableBanner(String command, int expectedExitCode) {
var consoleLauncher = new ConsoleLauncher((__, ___) -> null, printSink, printSink);
var consoleLauncher = new ConsoleLauncher(ConsoleTestExecutor::new, printSink, printSink);
var exitCode = consoleLauncher.run(command, "--disable-banner").getExitCode();

assertEquals(expectedExitCode, exitCode);
Expand Down

0 comments on commit bc862e0

Please sign in to comment.