|
29 | 29 | * Tests for {@link JobExecutionExitCodeGenerator}. |
30 | 30 | * |
31 | 31 | * @author Dave Syer |
32 | | - * @author Mahmoud Ben Hassine |
33 | 32 | */ |
34 | 33 | class JobExecutionExitCodeGeneratorTests { |
35 | 34 |
|
36 | 35 | private final JobExecutionExitCodeGenerator generator = new JobExecutionExitCodeGenerator(); |
37 | 36 |
|
38 | 37 | @Test |
39 | 38 | void testExitCodeForRunning() { |
40 | | - JobInstance jobInstance = new JobInstance(1L, "job"); |
41 | | - JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters()); |
42 | | - this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution)); |
| 39 | + this.generator.onApplicationEvent(new JobExecutionEvent(testJobExecution())); |
43 | 40 | assertThat(this.generator.getExitCode()).isOne(); |
44 | 41 | } |
45 | 42 |
|
46 | 43 | @Test |
47 | 44 | void testExitCodeForCompleted() { |
48 | | - JobInstance jobInstance = new JobInstance(1L, "job"); |
49 | | - JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters()); |
50 | | - jobExecution.setStatus(BatchStatus.COMPLETED); |
51 | | - this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution)); |
| 45 | + JobExecution execution = testJobExecution(); |
| 46 | + execution.setStatus(BatchStatus.COMPLETED); |
| 47 | + this.generator.onApplicationEvent(new JobExecutionEvent(execution)); |
52 | 48 | assertThat(this.generator.getExitCode()).isZero(); |
53 | 49 | } |
54 | 50 |
|
55 | 51 | @Test |
56 | 52 | void testExitCodeForFailed() { |
57 | | - JobInstance jobInstance = new JobInstance(1L, "job"); |
58 | | - JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters()); |
59 | | - jobExecution.setStatus(BatchStatus.FAILED); |
60 | | - this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution)); |
| 53 | + JobExecution execution = testJobExecution(); |
| 54 | + execution.setStatus(BatchStatus.FAILED); |
| 55 | + this.generator.onApplicationEvent(new JobExecutionEvent(execution)); |
61 | 56 | assertThat(this.generator.getExitCode()).isEqualTo(5); |
62 | 57 | } |
63 | 58 |
|
| 59 | + private static JobExecution testJobExecution() { |
| 60 | + JobInstance jobInstance = new JobInstance(1L, "job"); |
| 61 | + return new JobExecution(0L, jobInstance, new JobParameters()); |
| 62 | + } |
| 63 | + |
64 | 64 | } |
0 commit comments