1
1
/*
2
- * Copyright 2006-2017 the original author or authors.
2
+ * Copyright 2006-2018 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.
27
27
import java .util .List ;
28
28
29
29
import org .junit .Before ;
30
- import org .junit .Ignore ;
30
+ import org .junit .Rule ;
31
31
import org .junit .Test ;
32
+ import org .junit .rules .ExpectedException ;
32
33
import org .springframework .batch .core .BatchStatus ;
33
34
import org .springframework .batch .core .ChunkListener ;
34
35
import org .springframework .batch .core .ItemProcessListener ;
64
65
*/
65
66
public class SimpleStepFactoryBeanTests {
66
67
68
+ @ Rule
69
+ public ExpectedException expectedException = ExpectedException .none ();
70
+
67
71
private List <Exception > listened = new ArrayList <Exception >();
68
72
69
73
private SimpleJobRepository repository = new SimpleJobRepository (new MapJobInstanceDao (), new MapJobExecutionDao (),
@@ -78,7 +82,7 @@ public void write(List<? extends String> data) throws Exception {
78
82
}
79
83
};
80
84
81
- private ItemReader <String > reader ;
85
+ private ItemReader <String > reader = new ListItemReader <>( Arrays . asList ( "a" , "b" , "c" )) ;
82
86
83
87
private SimpleJob job = new SimpleJob ();
84
88
@@ -93,6 +97,28 @@ public void testMandatoryProperties() throws Exception {
93
97
new SimpleStepFactoryBean <String , String >().getObject ();
94
98
}
95
99
100
+ @ Test
101
+ public void testMandatoryReader () throws Exception {
102
+ SimpleStepFactoryBean <String , String > factory = new SimpleStepFactoryBean <>();
103
+ factory .setItemWriter (writer );
104
+
105
+ expectedException .expect (IllegalStateException .class );
106
+ expectedException .expectMessage ("ItemReader must be provided" );
107
+
108
+ factory .getObject ();
109
+ }
110
+
111
+ @ Test
112
+ public void testMandatoryWriter () throws Exception {
113
+ SimpleStepFactoryBean <String , String > factory = new SimpleStepFactoryBean <>();
114
+ factory .setItemReader (reader );
115
+
116
+ expectedException .expect (IllegalStateException .class );
117
+ expectedException .expectMessage ("ItemWriter must be provided" );
118
+
119
+ factory .getObject ();
120
+ }
121
+
96
122
@ Test
97
123
public void testSimpleJob () throws Exception {
98
124
0 commit comments