1616package org .springframework .batch .core .configuration .support ;
1717
1818import static org .junit .jupiter .api .Assertions .assertEquals ;
19+ import static org .junit .jupiter .api .Assertions .assertThrows ;
1920
21+ import org .junit .jupiter .api .Assertions ;
2022import org .junit .jupiter .api .Test ;
23+ import org .junit .jupiter .api .function .Executable ;
2124
2225import org .springframework .batch .core .configuration .DuplicateJobException ;
23- import org .springframework .batch .core .job .Job ;
26+ import org .springframework .batch .core .configuration .annotation .EnableBatchProcessing ;
27+ import org .springframework .batch .core .job .*;
2428import org .springframework .batch .core .configuration .JobRegistry ;
25- import org .springframework .batch .core .job .SimpleJob ;
29+ import org .springframework .batch .core .job .builder .JobBuilder ;
30+ import org .springframework .batch .core .repository .JobRepository ;
31+ import org .springframework .batch .core .step .StepSupport ;
2632import org .springframework .beans .factory .annotation .Autowired ;
33+ import org .springframework .context .ApplicationContext ;
34+ import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
35+ import org .springframework .context .annotation .Bean ;
36+ import org .springframework .context .annotation .Configuration ;
2737import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
2838
2939/**
@@ -44,4 +54,31 @@ void testRegistry() throws DuplicateJobException {
4454 assertEquals (job .getName (), jobRegistry .getJobNames ().iterator ().next ());
4555 }
4656
57+ @ Test
58+ void testDuplicateJobRegistration () {
59+ assertThrows (IllegalStateException .class ,
60+ () -> new AnnotationConfigApplicationContext (JobConfigurationWithDuplicateJobs .class ));
61+ }
62+
63+ @ Configuration
64+ @ EnableBatchProcessing
65+ static class JobConfigurationWithDuplicateJobs {
66+
67+ @ Bean
68+ Job job1 () {
69+ return new JobSupport ("sameJobNameOnPurpose" );
70+ }
71+
72+ @ Bean
73+ Job job2 () {
74+ return new JobSupport ("sameJobNameOnPurpose" );
75+ }
76+
77+ @ Bean
78+ public JobRegistry jobRegistry () {
79+ return new MapJobRegistry ();
80+ }
81+
82+ }
83+
4784}
0 commit comments