Skip to content

Commit 596ee70

Browse files
committed
Refine contribution #3932
* Add default methods in interfaces * Update tests/Javadoc * Optimize imports * Apply code style formatting
1 parent 5a35b03 commit 596ee70

File tree

8 files changed

+46
-33
lines changed

8 files changed

+46
-33
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,17 @@ default JobInstance getLastJobInstance(String jobName) {
9595
JobInstance getJobInstance(@Nullable Long instanceId);
9696

9797
/**
98-
* @param jobName {@link String} name for the jobInstance.
99-
* @param jobParameters {@link JobParameters} parameters for the jobInstance.
100-
* @return the {@link JobInstance} with this name and parameters, or null
98+
* @param jobName {@link String} name of the job.
99+
* @param jobParameters {@link JobParameters} parameters for the job instance.
100+
* @return the {@link JobInstance} with the given name and parameters, or
101+
* {@code null}.
101102
*
102103
* @since 5.0
103104
*/
104105
@Nullable
105-
JobInstance getJobInstance(String jobName, JobParameters jobParameters);
106+
default JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
107+
throw new UnsupportedOperationException();
108+
}
106109

107110
/**
108111
* Retrieve job executions by their job instance. The corresponding step executions

spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
* @author Will Schipp
4141
* @author Mahmoud Ben Hassine
4242
* @author Parikshit Dutta
43-
*
4443
* @see JobExplorer
4544
* @see JobInstanceDao
4645
* @see JobExecutionDao
@@ -191,8 +190,7 @@ public JobInstance getJobInstance(@Nullable Long instanceId) {
191190
/*
192191
* (non-Javadoc)
193192
*
194-
* @see
195-
* org.springframework.batch.core.explore.JobExplorer#getJobInstance(java
193+
* @see org.springframework.batch.core.explore.JobExplorer#getJobInstance(java
196194
* .lang.String, org.springframework.batch.core.JobParameters)
197195
*/
198196
@Nullable

spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,17 @@ JobExecution createJobExecution(String jobName, JobParameters jobParameters)
188188
void updateExecutionContext(JobExecution jobExecution);
189189

190190
/**
191-
* @param jobName {@link String} the name of the jobInstance
192-
* @param jobParameters {@link JobParameters} parameters identifying the {@link JobInstance}
193-
* @return the {@link JobInstance} with name and parameters, or null
191+
* @param jobName {@link String} name of the job.
192+
* @param jobParameters {@link JobParameters} parameters for the job instance.
193+
* @return the {@link JobInstance} with the given name and parameters, or
194+
* {@code null}.
194195
*
195196
* @since 5.0
196197
*/
197198
@Nullable
198-
JobInstance getJobInstance(String jobName, JobParameters jobParameters);
199+
default JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
200+
throw new UnsupportedOperationException();
201+
}
199202

200203
/**
201204
* @param jobInstance {@link JobInstance} instance containing the step executions.

spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
* @author Mahmoud Ben Hassine
5555
* @author Baris Cubukcuoglu
5656
* @author Parikshit Dutta
57-
*
5857
* @see JobRepository
5958
* @see JobInstanceDao
6059
* @see JobExecutionDao

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobRepository.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
* @author David Turanski
3434
* @author Mahmoud Ben Hassine
3535
* @author Parikshit Dutta
36-
*
3736
* @since 2.0.1
3837
*/
3938
public class DummyJobRepository implements JobRepository, BeanNameAware {

spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertNull;
2121
import static org.junit.jupiter.api.Assertions.assertThrows;
22-
import static org.junit.Assert.assertEquals;
23-
import static org.junit.Assert.assertNull;
24-
import static org.mockito.ArgumentMatchers.any;
25-
import static org.mockito.ArgumentMatchers.anyString;
2622
import static org.mockito.Mockito.mock;
2723
import static org.mockito.Mockito.verify;
2824
import static org.mockito.Mockito.when;
@@ -155,11 +151,18 @@ void testGetJobInstance() {
155151
}
156152

157153
@Test
158-
public void testGetJobInstanceWithNameAndParameters() throws Exception {
159-
when(jobInstanceDao.getJobInstance("job", new JobParameters())).thenReturn(jobInstance);
160-
JobInstance jobInstance = jobExplorer.getJobInstance("job", new JobParameters());
161-
verify(jobInstanceDao).getJobInstance(anyString(), any(JobParameters.class));
162-
assertEquals(jobInstance, jobInstance);
154+
public void testGetJobInstanceWithNameAndParameters() {
155+
// given
156+
String jobName = "job";
157+
JobParameters jobParameters = new JobParameters();
158+
159+
// when
160+
when(jobInstanceDao.getJobInstance(jobName, jobParameters)).thenReturn(this.jobInstance);
161+
JobInstance jobInstance = jobExplorer.getJobInstance(jobName, jobParameters);
162+
163+
// then
164+
verify(jobInstanceDao).getJobInstance(jobName, jobParameters);
165+
assertEquals(this.jobInstance, jobInstance);
163166
}
164167

165168
@Test

spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import static org.junit.jupiter.api.Assertions.assertTrue;
2222
import static org.junit.jupiter.api.Assertions.assertFalse;
2323
import static org.junit.jupiter.api.Assertions.assertEquals;
24-
import static org.mockito.ArgumentMatchers.any;
25-
import static org.mockito.ArgumentMatchers.anyString;
2624
import static org.mockito.Mockito.mock;
2725
import static org.mockito.Mockito.verify;
2826
import static org.mockito.Mockito.when;
@@ -332,12 +330,19 @@ public void testUpgradeStopping() {
332330
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
333331
}
334332

335-
336333
@Test
337-
public void testGetJobInstanceWithNameAndParameters() throws Exception {
338-
when(jobInstanceDao.getJobInstance("job", new JobParameters())).thenReturn(jobInstance);
339-
JobInstance jobInstance = jobRepository.getJobInstance("job", new JobParameters());
340-
verify(jobInstanceDao).getJobInstance(anyString(), any(JobParameters.class));
341-
assertEquals(jobInstance, jobInstance);
334+
public void testGetJobInstanceWithNameAndParameters() {
335+
// given
336+
String jobName = "job";
337+
JobParameters jobParameters = new JobParameters();
338+
339+
// when
340+
when(jobInstanceDao.getJobInstance(jobName, jobParameters)).thenReturn(this.jobInstance);
341+
JobInstance jobInstance = jobRepository.getJobInstance(jobName, jobParameters);
342+
343+
// then
344+
verify(jobInstanceDao).getJobInstance(jobName, jobParameters);
345+
assertEquals(this.jobInstance, jobInstance);
342346
}
347+
343348
}

spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@ public JobExecution createJobExecution(String jobName, JobParameters jobParamete
4848

4949
/*
5050
* (non-Javadoc)
51-
* @see org.springframework.batch.core.repository.JobRepository#getJobInstance(java.lang.String,
52-
* org.springframework.batch.core.JobParameters)
51+
*
52+
* @see
53+
* org.springframework.batch.core.repository.JobRepository#getJobInstance(java.lang.
54+
* String, org.springframework.batch.core.JobParameters)
5355
*/
5456
public JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
5557
return null;
5658
}
5759

58-
/* (non-Javadoc)
60+
/*
61+
* (non-Javadoc)
5962
*
6063
* @see
6164
* org.springframework.batch.core.repository.JobRepository#getLastStepExecution(org.

0 commit comments

Comments
 (0)