From bc862e01288a8392992c32c03dd8f25cb1b6023f Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 17 Aug 2023 16:17:10 +0200 Subject: [PATCH] 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. --- .../org/junit/platform/console/ConsoleLauncherTests.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platform-tests/src/test/java/org/junit/platform/console/ConsoleLauncherTests.java b/platform-tests/src/test/java/org/junit/platform/console/ConsoleLauncherTests.java index 80ec67b578a1..00fed18c5351 100644 --- a/platform-tests/src/test/java/org/junit/platform/console/ConsoleLauncherTests.java +++ b/platform-tests/src/test/java/org/junit/platform/console/ConsoleLauncherTests.java @@ -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( @@ -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);