From 8cd7c2277f50e98156561044890189dc414737ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Fri, 10 Oct 2025 18:20:22 +0200 Subject: [PATCH] Polish "Start building against Spring Batch 6.0.0-RC1 snapshots" See gh-47477 --- .../JobLauncherApplicationRunner.java | 5 ++-- .../JobExecutionExitCodeGeneratorTests.java | 24 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java b/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java index 37b28c21864..b3c29f846a4 100644 --- a/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java +++ b/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java @@ -179,9 +179,8 @@ public class JobLauncherApplicationRunner if (this.jobRegistry != null && StringUtils.hasText(this.jobName)) { if (!isLocalJob(this.jobName)) { Job job = this.jobRegistry.getJob(this.jobName); - if (job != null) { - execute(job, jobParameters); - } + Assert.notNull(job, () -> "No job found with name '" + this.jobName + "'"); + execute(job, jobParameters); } } } diff --git a/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java b/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java index 0c250d0e926..91c0cb0f72b 100644 --- a/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java +++ b/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java @@ -29,7 +29,6 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link JobExecutionExitCodeGenerator}. * * @author Dave Syer - * @author Mahmoud Ben Hassine */ class JobExecutionExitCodeGeneratorTests { @@ -37,28 +36,29 @@ class JobExecutionExitCodeGeneratorTests { @Test void testExitCodeForRunning() { - JobInstance jobInstance = new JobInstance(1L, "job"); - JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters()); - this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution)); + this.generator.onApplicationEvent(new JobExecutionEvent(testJobExecution())); assertThat(this.generator.getExitCode()).isOne(); } @Test void testExitCodeForCompleted() { - JobInstance jobInstance = new JobInstance(1L, "job"); - JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters()); - jobExecution.setStatus(BatchStatus.COMPLETED); - this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution)); + JobExecution execution = testJobExecution(); + execution.setStatus(BatchStatus.COMPLETED); + this.generator.onApplicationEvent(new JobExecutionEvent(execution)); assertThat(this.generator.getExitCode()).isZero(); } @Test void testExitCodeForFailed() { - JobInstance jobInstance = new JobInstance(1L, "job"); - JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters()); - jobExecution.setStatus(BatchStatus.FAILED); - this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution)); + JobExecution execution = testJobExecution(); + execution.setStatus(BatchStatus.FAILED); + this.generator.onApplicationEvent(new JobExecutionEvent(execution)); assertThat(this.generator.getExitCode()).isEqualTo(5); } + private static JobExecution testJobExecution() { + JobInstance jobInstance = new JobInstance(1L, "job"); + return new JobExecution(0L, jobInstance, new JobParameters()); + } + }