Skip to content

Commit bc862e0

Browse files
committed
Avoid NullPointerExceptions in console output in tests
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.
1 parent 4eca30b commit bc862e0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

platform-tests/src/test/java/org/junit/platform/console/ConsoleLauncherTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ class ConsoleLauncherTests {
3434
@ParameterizedTest(name = "{0}")
3535
@MethodSource("commandsWithEmptyOptionExitCodes")
3636
void displayHelp(String command) {
37-
var consoleLauncher = new ConsoleLauncher((__, ___) -> null, printSink, printSink);
37+
var consoleLauncher = new ConsoleLauncher(ConsoleTestExecutor::new, printSink, printSink);
3838
var exitCode = consoleLauncher.run(command, "--help").getExitCode();
3939

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

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

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

6060
assertEquals(expectedExitCode, exitCode);

0 commit comments

Comments
 (0)