1
1
/*
2
- * Copyright 2020-2022 the original author or authors.
2
+ * Copyright 2020-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
24
24
import org .springframework .batch .core .JobExecution ;
25
25
import org .springframework .batch .core .JobExecutionListener ;
26
26
import org .springframework .batch .core .JobParameters ;
27
+ import org .springframework .batch .core .Step ;
27
28
import org .springframework .batch .core .annotation .AfterJob ;
28
29
import org .springframework .batch .core .annotation .BeforeJob ;
29
30
import org .springframework .batch .core .configuration .annotation .EnableBatchProcessing ;
31
+ import org .springframework .batch .core .job .SimpleJob ;
30
32
import org .springframework .batch .core .launch .JobLauncher ;
31
33
import org .springframework .batch .core .repository .JobRepository ;
34
+ import org .springframework .batch .core .step .JobRepositorySupport ;
32
35
import org .springframework .batch .core .step .builder .StepBuilder ;
33
36
import org .springframework .batch .repeat .RepeatStatus ;
34
37
import org .springframework .context .ApplicationContext ;
40
43
import org .springframework .transaction .PlatformTransactionManager ;
41
44
42
45
import static org .junit .jupiter .api .Assertions .assertEquals ;
46
+ import static org .assertj .core .api .Assertions .assertThat ;
43
47
44
48
/**
45
49
* @author Mahmoud Ben Hassine
50
+ * @author Minkuk Jo
46
51
*/
47
52
class JobBuilderTests {
48
53
@@ -65,6 +70,24 @@ void testListeners() throws Exception {
65
70
66
71
}
67
72
73
+ @ Test
74
+ void testJobDescription () {
75
+ // given
76
+ ApplicationContext context = new AnnotationConfigApplicationContext (MyJobConfiguration .class );
77
+ JobRepository jobRepository = context .getBean (JobRepository .class );
78
+ PlatformTransactionManager transactionManager = context .getBean (PlatformTransactionManager .class );
79
+ Step step = new StepBuilder ("step" , jobRepository )
80
+ .tasklet ((contribution , chunkContext ) -> RepeatStatus .FINISHED , transactionManager )
81
+ .build ();
82
+
83
+ // when
84
+ Job job = new JobBuilder ("job" , jobRepository ).description ("This is a test job" ).start (step ).build ();
85
+
86
+ // then
87
+ assertThat (job ).isInstanceOf (SimpleJob .class );
88
+ assertThat (((SimpleJob ) job ).getDescription ()).isEqualTo ("This is a test job" );
89
+ }
90
+
68
91
@ Configuration
69
92
@ EnableBatchProcessing
70
93
static class MyJobConfiguration {
0 commit comments