diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/parameters/JobParameter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/parameters/JobParameter.java index 30417e60f0..ab40f81c17 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/parameters/JobParameter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/parameters/JobParameter.java @@ -47,7 +47,7 @@ public record JobParameter(String name, T value, Class type, boolean ident * @since 6.0 */ public JobParameter { - Assert.notNull(value, "name must not be null"); + Assert.notNull(name, "name must not be null"); Assert.notNull(value, "value must not be null"); Assert.notNull(type, "type must not be null"); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/JobParameterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/JobParameterTests.java index ce4d22b220..f8e1bd59e4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/JobParameterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/JobParameterTests.java @@ -15,15 +15,14 @@ */ package org.springframework.batch.core; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.util.Date; import org.junit.jupiter.api.Test; import org.springframework.batch.core.job.parameters.JobParameter; +import static org.junit.jupiter.api.Assertions.*; + /** * @author Lucas Ward * @author Mahmoud Ben Hassine @@ -31,6 +30,27 @@ */ class JobParameterTests { + @Test + void testConstructorNameNotNull() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> new JobParameter<>(null, "test", String.class, true)); + assertEquals("name must not be null", exception.getMessage()); + } + + @Test + void testConstructorValueNotNull() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> new JobParameter<>("param", null, String.class, true)); + assertEquals("value must not be null", exception.getMessage()); + } + + @Test + void testConstructorTypeNotNull() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> new JobParameter<>("param", "test", null, true)); + assertEquals("type must not be null", exception.getMessage()); + } + @Test void testStringParameter() { JobParameter jobParameter = new JobParameter<>("param", "test", String.class, true);