From c65a259637ce80ca4aa6e13547a83f745c32a223 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Mon, 6 Oct 2025 11:34:17 +0200 Subject: [PATCH] Add nullability annotations to tests in module/spring-boot-batch-jdbc See gh-47263 --- module/spring-boot-batch-jdbc/build.gradle | 4 ++++ .../BatchJdbcAutoConfigurationTests.java | 22 +++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/module/spring-boot-batch-jdbc/build.gradle b/module/spring-boot-batch-jdbc/build.gradle index 659ec57a1fe..3fe15a12505 100644 --- a/module/spring-boot-batch-jdbc/build.gradle +++ b/module/spring-boot-batch-jdbc/build.gradle @@ -47,3 +47,7 @@ dependencies { testRuntimeOnly("com.h2database:h2") testRuntimeOnly("com.zaxxer:HikariCP") } + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} diff --git a/module/spring-boot-batch-jdbc/src/test/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchJdbcAutoConfigurationTests.java b/module/spring-boot-batch-jdbc/src/test/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchJdbcAutoConfigurationTests.java index 468ed9de91d..ae9a03b73de 100644 --- a/module/spring-boot-batch-jdbc/src/test/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchJdbcAutoConfigurationTests.java +++ b/module/spring-boot-batch-jdbc/src/test/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchJdbcAutoConfigurationTests.java @@ -189,9 +189,10 @@ class BatchJdbcAutoConfigurationTests { .run((context) -> { assertThat(context).hasSingleBean(JobOperator.class); context.getBean(JobLauncherApplicationRunner.class).run(); - assertThat(context.getBean(JobRepository.class) - .getLastJobExecution("discreteRegisteredJob", new JobParameters()) - .getStatus()).isEqualTo(BatchStatus.COMPLETED); + JobExecution lastJobExecution = context.getBean(JobRepository.class) + .getLastJobExecution("discreteRegisteredJob", new JobParameters()); + assertThat(lastJobExecution).isNotNull(); + assertThat(lastJobExecution.getStatus()).isEqualTo(BatchStatus.COMPLETED); }); } @@ -213,8 +214,11 @@ class BatchJdbcAutoConfigurationTests { this.contextRunner.withUserConfiguration(MultipleJobConfiguration.class, EmbeddedDataSourceConfiguration.class) .run((context) -> { assertThat(context).hasFailed(); - assertThat(context.getStartupFailure().getCause().getMessage()) - .contains("Job name must be specified in case of multiple jobs"); + Throwable startupFailure = context.getStartupFailure(); + assertThat(startupFailure).isNotNull(); + Throwable cause = startupFailure.getCause(); + assertThat(cause).isNotNull(); + assertThat(cause.getMessage()).contains("Job name must be specified in case of multiple jobs"); }); } @@ -642,7 +646,7 @@ class BatchJdbcAutoConfigurationTests { @Override public Step getStep(String stepName) { - return null; + return mock(Step.class); } @Override @@ -679,7 +683,7 @@ class BatchJdbcAutoConfigurationTests { @Override public Step getStep(String stepName) { - return null; + return mock(Step.class); } @Override @@ -710,7 +714,7 @@ class BatchJdbcAutoConfigurationTests { @Override public Step getStep(String stepName) { - return null; + return mock(Step.class); } @Override @@ -756,7 +760,7 @@ class BatchJdbcAutoConfigurationTests { @Override public Step getStep(String stepName) { - return null; + return mock(Step.class); } @Override