Skip to content

Commit 0c3e028

Browse files
author
Fabrice Bibonne
committed
fix(java format)
1 parent ce4ec96 commit 0c3e028

File tree

6 files changed

+99
-87
lines changed

6 files changed

+99
-87
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public final void execute(JobExecution execution) {
372372
}
373373
}
374374

375-
protected abstract void checkStepNamesUnicity() throws AlreadyUsedStepNameException ;
375+
protected abstract void checkStepNamesUnicity() throws AlreadyUsedStepNameException;
376376

377377
private void stopObservation(JobExecution execution, Observation observation) {
378378
List<Throwable> throwables = execution.getFailureExceptions();
@@ -431,9 +431,10 @@ else if (ex instanceof NoSuchJobException || ex.getCause() instanceof NoSuchJobE
431431
return exitStatus;
432432
}
433433

434-
protected static void addToMapCheckingUnicity(Map<String, Step> map, Step step, String name) throws AlreadyUsedStepNameException {
435-
map.merge(name, step, (old, value)->{
436-
if (!old.equals(value)){
434+
protected static void addToMapCheckingUnicity(Map<String, Step> map, Step step, String name)
435+
throws AlreadyUsedStepNameException {
436+
map.merge(name, step, (old, value) -> {
437+
if (!old.equals(value)) {
437438
throw new AlreadyUsedStepNameException(name);
438439
}
439440
return old;

spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleJob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protected void doExecute(JobExecution execution)
145145

146146
@Override
147147
protected void checkStepNamesUnicity() {
148-
//noop : steps of SimpleJob can share the same name
148+
// noop : steps of SimpleJob can share the same name
149149
}
150150

151151
}

spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public Step getStep(String stepName) {
7979
return stepMap.get(stepName);
8080
}
8181

82-
8382
/**
8483
* Initialize the step names
8584
*/
@@ -98,14 +97,10 @@ private void findStepsThrowingIfNameNotUnique(Flow flow) {
9897
addToMapCheckingUnicity(this.stepMap, locator.getStep(name), name);
9998
}
10099
}
101-
//TODO remove this else bock ? not executed during tests : the only State which implements StepHolder is StepState which already implements StepLocator
102-
/*
103-
Tests Coverage
104-
Hits : 30
105-
state instanceof StepHolder
106-
true hits: 0
107-
false hits : 30
108-
*/
100+
// TODO remove this else bock ? not executed during tests : the only State
101+
// which implements StepHolder is StepState which already implements
102+
// StepLocator
103+
// within tests coverage `state instanceof StepHolder` is false 30 times/30
109104
else if (state instanceof StepHolder stepHolder) {
110105
Step step = stepHolder.getStep();
111106
addToMapCheckingUnicity(this.stepMap, step, step.getName());

spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ protected void doExecute(JobExecution execution) throws JobExecutionException {
205205
}
206206

207207
@Override
208-
protected void checkStepNamesUnicity(){
208+
protected void checkStepNamesUnicity() {
209209
}
210210

211211
@Override

spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -514,18 +514,18 @@ void testGetMultipleJobParameters() throws Exception {
514514
}
515515

516516
@Test
517-
public void testMultipleStepsWithSameName(){
517+
public void testMultipleStepsWithSameName() {
518518
job.setName("MultipleStepsWithSameName");
519-
String sharedName="stepName";
520-
final List<String> executionsCallbacks=new ArrayList<>();
521-
StubStep sharedNameStep1=new StubStep(sharedName, jobRepository);
522-
sharedNameStep1.setCallback(()->executionsCallbacks.add("step1"));
519+
String sharedName = "stepName";
520+
final List<String> executionsCallbacks = new ArrayList<>();
521+
StubStep sharedNameStep1 = new StubStep(sharedName, jobRepository);
522+
sharedNameStep1.setCallback(() -> executionsCallbacks.add("step1"));
523523
job.addStep(sharedNameStep1);
524-
StubStep sharedNameStep2=new StubStep(sharedName, jobRepository);
525-
sharedNameStep2.setCallback(()->executionsCallbacks.add("step2"));
524+
StubStep sharedNameStep2 = new StubStep(sharedName, jobRepository);
525+
sharedNameStep2.setCallback(() -> executionsCallbacks.add("step2"));
526526
job.addStep(sharedNameStep2);
527-
StubStep sharedNameStep3=new StubStep(sharedName, jobRepository);
528-
sharedNameStep3.setCallback(()->executionsCallbacks.add("step3"));
527+
StubStep sharedNameStep3 = new StubStep(sharedName, jobRepository);
528+
sharedNameStep3.setCallback(() -> executionsCallbacks.add("step3"));
529529
job.addStep(sharedNameStep3);
530530
job.execute(jobExecution);
531531
assertEquals(List.of("step1", "step2", "step3"), executionsCallbacks);

spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java

Lines changed: 79 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ public void execute(StepExecution stepExecution)
109109
@BeforeEach
110110
void init() throws Exception {
111111
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
112-
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
113-
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
114-
.build();
112+
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
113+
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
114+
.build();
115115
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
116116
factory.setDataSource(embeddedDatabase);
117117
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));
@@ -123,10 +123,10 @@ void init() throws Exception {
123123
@Test
124124
void testBuildOnOneLine() {
125125
FlowJobBuilder builder = new JobBuilder("flow", jobRepository).start(step1)
126-
.on("COMPLETED")
127-
.to(step2)
128-
.end()
129-
.preventRestart();
126+
.on("COMPLETED")
127+
.to(step2)
128+
.end()
129+
.preventRestart();
130130
builder.build().execute(execution);
131131
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
132132
assertEquals(2, execution.getStepExecutions().size());
@@ -200,9 +200,9 @@ void testBuildSplitUsingStartAndAdd_BATCH_2346() {
200200
Flow subflow1 = new FlowBuilder<Flow>("subflow1").from(step2).end();
201201
Flow subflow2 = new FlowBuilder<Flow>("subflow2").from(step3).end();
202202
Flow splitflow = new FlowBuilder<Flow>("splitflow").start(subflow1)
203-
.split(new SimpleAsyncTaskExecutor())
204-
.add(subflow2)
205-
.build();
203+
.split(new SimpleAsyncTaskExecutor())
204+
.add(subflow2)
205+
.build();
206206

207207
FlowJobBuilder builder = new JobBuilder("flow", jobRepository).start(splitflow).end();
208208
builder.preventRestart().build().execute(execution);
@@ -215,8 +215,8 @@ void testBuildSplit_BATCH_2282() {
215215
Flow flow1 = new FlowBuilder<Flow>("subflow1").from(step1).end();
216216
Flow flow2 = new FlowBuilder<Flow>("subflow2").from(step2).end();
217217
Flow splitFlow = new FlowBuilder<Flow>("splitflow").split(new SimpleAsyncTaskExecutor())
218-
.add(flow1, flow2)
219-
.build();
218+
.add(flow1, flow2)
219+
.build();
220220
FlowJobBuilder builder = new JobBuilder("flow", jobRepository).start(splitFlow).end();
221221
builder.preventRestart().build().execute(execution);
222222
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
@@ -363,15 +363,28 @@ void testBuildWithJobScopedStep() throws Exception {
363363

364364
// https://github.com/spring-projects/spring-batch/issues/3757#issuecomment-1821593539
365365
@Test
366-
void testStepNamesMustBeUniqueWithinFlowDefinition() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
366+
void testStepNamesMustBeUniqueWithinFlowDefinition() throws JobInstanceAlreadyCompleteException,
367+
JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
367368
ApplicationContext context = new AnnotationConfigApplicationContext(JobConfigurationForStepNameUnique.class);
368369
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
369370
Job job = context.getBean(Job.class);
370-
JobExecution jobExecution=jobLauncher.run(job, new JobParametersBuilder().addLong("random", 2L).addString("stepTwo.name", JobConfigurationForStepNameUnique.SHARED_NAME).toJobParameters());
371-
assertTrue(jobExecution.getAllFailureExceptions().stream().map(Object::getClass).anyMatch(AlreadyUsedStepNameException.class::equals));
371+
JobExecution jobExecution = jobLauncher.run(job,
372+
new JobParametersBuilder().addLong("random", 2L)
373+
.addString("stepTwo.name", JobConfigurationForStepNameUnique.SHARED_NAME)
374+
.toJobParameters());
375+
assertTrue(jobExecution.getAllFailureExceptions()
376+
.stream()
377+
.map(Object::getClass)
378+
.anyMatch(AlreadyUsedStepNameException.class::equals));
372379
assertEquals(ExitStatus.FAILED.getExitCode(), jobExecution.getExitStatus().getExitCode());
373-
jobExecution=jobLauncher.run(job, new JobParametersBuilder().addLong("random", 1L).addString("stepTwo.name", JobConfigurationForStepNameUnique.SHARED_NAME).toJobParameters());
374-
assertTrue(jobExecution.getAllFailureExceptions().stream().map(Object::getClass).anyMatch(AlreadyUsedStepNameException.class::equals));
380+
jobExecution = jobLauncher.run(job,
381+
new JobParametersBuilder().addLong("random", 1L)
382+
.addString("stepTwo.name", JobConfigurationForStepNameUnique.SHARED_NAME)
383+
.toJobParameters());
384+
assertTrue(jobExecution.getAllFailureExceptions()
385+
.stream()
386+
.map(Object::getClass)
387+
.anyMatch(AlreadyUsedStepNameException.class::equals));
375388
assertEquals(ExitStatus.FAILED.getExitCode(), jobExecution.getExitStatus().getExitCode());
376389
}
377390

@@ -383,96 +396,99 @@ static class JobConfigurationForStepNameUnique {
383396

384397
private static final Log logger = LogFactory.getLog(FlowJobBuilderTests.class);
385398

386-
387399
@Bean
388400
@JobScope
389401
public Step conditionalStep(JobRepository jobRepository, PlatformTransactionManager transactionManager,
390-
@Value("#{jobParameters['random']}") Integer random) {
391-
return new StepBuilder("conditionalStep", jobRepository).tasklet(
392-
(StepContribution contribution, ChunkContext chunkContext) -> {
393-
String exitStatus = (random % 2 == 0) ? "EVEN" : "ODD";
394-
logger.info("'conditionalStep' with exitStatus " + exitStatus);
395-
contribution.setExitStatus(new ExitStatus(exitStatus));
396-
return RepeatStatus.FINISHED;
397-
}, transactionManager
398-
).build();
402+
@Value("#{jobParameters['random']}") Integer random) {
403+
return new StepBuilder("conditionalStep", jobRepository)
404+
.tasklet((StepContribution contribution, ChunkContext chunkContext) -> {
405+
String exitStatus = (random % 2 == 0) ? "EVEN" : "ODD";
406+
logger.info("'conditionalStep' with exitStatus " + exitStatus);
407+
contribution.setExitStatus(new ExitStatus(exitStatus));
408+
return RepeatStatus.FINISHED;
409+
}, transactionManager)
410+
.build();
399411
}
400412

401413
@Bean
402414
@JobScope
403415
public Step stepTwo(JobRepository jobRepository, PlatformTransactionManager transactionManager,
404-
@Value("#{jobParameters['stepTwo.name']}") String name) {
416+
@Value("#{jobParameters['stepTwo.name']}") String name) {
405417
return new StepBuilder(name, jobRepository)
406-
.tasklet((StepContribution contribution, ChunkContext chunkContext) -> {
407-
logger.info("Hello from stepTwo");
408-
return RepeatStatus.FINISHED;
409-
}, transactionManager)
410-
.build();
418+
.tasklet((StepContribution contribution, ChunkContext chunkContext) -> {
419+
logger.info("Hello from stepTwo");
420+
return RepeatStatus.FINISHED;
421+
}, transactionManager)
422+
.build();
411423
}
412424

413425
@Bean
414426
public Step stepThree(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
415427
return new StepBuilder(SHARED_NAME, jobRepository)
416-
.tasklet((StepContribution contribution, ChunkContext chunkContext) -> {
417-
logger.info("Hello from stepThree");
418-
return RepeatStatus.FINISHED;
419-
}, transactionManager)
420-
.build();
428+
.tasklet((StepContribution contribution, ChunkContext chunkContext) -> {
429+
logger.info("Hello from stepThree");
430+
return RepeatStatus.FINISHED;
431+
}, transactionManager)
432+
.build();
421433
}
422434

423435
@Bean
424436
public Step stepFour(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
425437
return new StepBuilder(SHARED_NAME, jobRepository)
426-
.tasklet((StepContribution contribution, ChunkContext chunkContext) -> {
427-
logger.info("Hello from stepFour");
428-
return RepeatStatus.FINISHED;
429-
}, transactionManager)
430-
.build();
438+
.tasklet((StepContribution contribution, ChunkContext chunkContext) -> {
439+
logger.info("Hello from stepFour");
440+
return RepeatStatus.FINISHED;
441+
}, transactionManager)
442+
.build();
431443
}
432444

433445
@Bean
434446
public Job job(JobRepository jobRepository, @Qualifier("conditionalStep") Step conditionalStep,
435-
@Qualifier("stepFour") Step step4, @Qualifier("stepTwo") Step step2,
436-
@Qualifier("stepThree") Step step3) {
447+
@Qualifier("stepFour") Step step4, @Qualifier("stepTwo") Step step2,
448+
@Qualifier("stepThree") Step step3) {
437449
JobBuilder jobBuilder = new JobBuilder("flow", jobRepository);
438450
return jobBuilder.start(conditionalStep)
439-
.on("ODD").to(step2)
440-
.from(conditionalStep).on("EVEN").to(step3)
441-
.from(step3)
442-
.next(step4)
443-
.from(step2).next(step4).end().build();
451+
.on("ODD")
452+
.to(step2)
453+
.from(conditionalStep)
454+
.on("EVEN")
455+
.to(step3)
456+
.from(step3)
457+
.next(step4)
458+
.from(step2)
459+
.next(step4)
460+
.end()
461+
.build();
444462
}
445463

446464
@Bean
447465
public DataSource dataSource() {
448466
return new EmbeddedDatabaseBuilder().addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
449-
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
450-
.generateUniqueName(true)
451-
.build();
467+
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
468+
.generateUniqueName(true)
469+
.build();
452470
}
453471

454472
@Bean
455473
public JdbcTransactionManager transactionManager(DataSource dataSource) {
456474
return new JdbcTransactionManager(dataSource);
457475
}
458476

459-
460477
}
461478

462-
463479
@EnableBatchProcessing
464480
@Configuration
465481
static class JobConfiguration {
466482

467483
@Bean
468484
@JobScope
469485
public Step step(JobRepository jobRepository, PlatformTransactionManager transactionManager,
470-
@Value("#{jobParameters['chunkSize']}") Integer chunkSize) {
486+
@Value("#{jobParameters['chunkSize']}") Integer chunkSize) {
471487
return new StepBuilder("step", jobRepository).<Integer, Integer>chunk(chunkSize, transactionManager)
472-
.reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4)))
473-
.writer(items -> {
474-
})
475-
.build();
488+
.reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4)))
489+
.writer(items -> {
490+
})
491+
.build();
476492
}
477493

478494
@Bean
@@ -484,9 +500,9 @@ public Job job(JobRepository jobRepository, PlatformTransactionManager transacti
484500
@Bean
485501
public DataSource dataSource() {
486502
return new EmbeddedDatabaseBuilder().addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
487-
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
488-
.generateUniqueName(true)
489-
.build();
503+
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
504+
.generateUniqueName(true)
505+
.build();
490506
}
491507

492508
@Bean

0 commit comments

Comments
 (0)