diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java index bdfa4e14a..05ea95b6d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java @@ -95,14 +95,17 @@ public interface JobExplorer { JobInstance getJobInstance(@Nullable Long instanceId); /** - * @param jobName {@link String} name for the jobInstance. - * @param jobParameters {@link JobParameters} parameters for the jobInstance. - * @return the {@link JobInstance} with this name and parameters, or null + * @param jobName {@link String} name of the job. + * @param jobParameters {@link JobParameters} parameters for the job instance. + * @return the {@link JobInstance} with the given name and parameters, or + * {@code null}. * * @since 5.0 */ @Nullable - JobInstance getJobInstance(String jobName, JobParameters jobParameters); + default JobInstance getJobInstance(String jobName, JobParameters jobParameters) { + throw new UnsupportedOperationException(); + } /** * Retrieve job executions by their job instance. The corresponding step executions diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java index 0a78e13a0..21c9f9d57 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java @@ -40,7 +40,6 @@ import java.util.Set; * @author Will Schipp * @author Mahmoud Ben Hassine * @author Parikshit Dutta - * * @see JobExplorer * @see JobInstanceDao * @see JobExecutionDao @@ -191,8 +190,7 @@ public class SimpleJobExplorer implements JobExplorer { /* * (non-Javadoc) * - * @see - * org.springframework.batch.core.explore.JobExplorer#getJobInstance(java + * @see org.springframework.batch.core.explore.JobExplorer#getJobInstance(java * .lang.String, org.springframework.batch.core.JobParameters) */ @Nullable diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java index d83daa8af..ec1589452 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java @@ -188,14 +188,17 @@ public interface JobRepository { void updateExecutionContext(JobExecution jobExecution); /** - * @param jobName {@link String} the name of the jobInstance - * @param jobParameters {@link JobParameters} parameters identifying the {@link JobInstance} - * @return the {@link JobInstance} with name and parameters, or null + * @param jobName {@link String} name of the job. + * @param jobParameters {@link JobParameters} parameters for the job instance. + * @return the {@link JobInstance} with the given name and parameters, or + * {@code null}. * * @since 5.0 */ @Nullable - JobInstance getJobInstance(String jobName, JobParameters jobParameters); + default JobInstance getJobInstance(String jobName, JobParameters jobParameters) { + throw new UnsupportedOperationException(); + } /** * @param jobInstance {@link JobInstance} instance containing the step executions. diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java index d04bed856..53caabeaf 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java @@ -54,7 +54,6 @@ import java.util.List; * @author Mahmoud Ben Hassine * @author Baris Cubukcuoglu * @author Parikshit Dutta - * * @see JobRepository * @see JobInstanceDao * @see JobExecutionDao diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobRepository.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobRepository.java index bfca29bfc..b6745f7c1 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobRepository.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobRepository.java @@ -33,7 +33,6 @@ import org.springframework.lang.Nullable; * @author David Turanski * @author Mahmoud Ben Hassine * @author Parikshit Dutta - * * @since 2.0.1 */ public class DummyJobRepository implements JobRepository, BeanNameAware { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java index 6cd70bfcc..8b275d9c7 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java @@ -19,10 +19,6 @@ package org.springframework.batch.core.explore.support; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -155,11 +151,18 @@ class SimpleJobExplorerTests { } @Test - public void testGetJobInstanceWithNameAndParameters() throws Exception { - when(jobInstanceDao.getJobInstance("job", new JobParameters())).thenReturn(jobInstance); - JobInstance jobInstance = jobExplorer.getJobInstance("job", new JobParameters()); - verify(jobInstanceDao).getJobInstance(anyString(), any(JobParameters.class)); - assertEquals(jobInstance, jobInstance); + public void testGetJobInstanceWithNameAndParameters() { + // given + String jobName = "job"; + JobParameters jobParameters = new JobParameters(); + + // when + when(jobInstanceDao.getJobInstance(jobName, jobParameters)).thenReturn(this.jobInstance); + JobInstance jobInstance = jobExplorer.getJobInstance(jobName, jobParameters); + + // then + verify(jobInstanceDao).getJobInstance(jobName, jobParameters); + assertEquals(this.jobInstance, jobInstance); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java index 2d277981c..10ca56f3e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java @@ -21,8 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -332,12 +330,19 @@ class SimpleJobRepositoryTests { assertEquals(BatchStatus.STOPPED, jobExecution.getStatus()); } - @Test - public void testGetJobInstanceWithNameAndParameters() throws Exception { - when(jobInstanceDao.getJobInstance("job", new JobParameters())).thenReturn(jobInstance); - JobInstance jobInstance = jobRepository.getJobInstance("job", new JobParameters()); - verify(jobInstanceDao).getJobInstance(anyString(), any(JobParameters.class)); - assertEquals(jobInstance, jobInstance); + public void testGetJobInstanceWithNameAndParameters() { + // given + String jobName = "job"; + JobParameters jobParameters = new JobParameters(); + + // when + when(jobInstanceDao.getJobInstance(jobName, jobParameters)).thenReturn(this.jobInstance); + JobInstance jobInstance = jobRepository.getJobInstance(jobName, jobParameters); + + // then + verify(jobInstanceDao).getJobInstance(jobName, jobParameters); + assertEquals(this.jobInstance, jobInstance); } + } diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java index 9617f64f3..5b84e85ee 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java @@ -48,14 +48,17 @@ public class JobRepositorySupport implements JobRepository { /* * (non-Javadoc) - * @see org.springframework.batch.core.repository.JobRepository#getJobInstance(java.lang.String, - * org.springframework.batch.core.JobParameters) + * + * @see + * org.springframework.batch.core.repository.JobRepository#getJobInstance(java.lang. + * String, org.springframework.batch.core.JobParameters) */ public JobInstance getJobInstance(String jobName, JobParameters jobParameters) { return null; } - /* (non-Javadoc) + /* + * (non-Javadoc) * * @see * org.springframework.batch.core.repository.JobRepository#getLastStepExecution(org.