Skip to content

Commit f0c60a3

Browse files
committed
BATCH-2624: add tests on mandatory item reader/writer
1 parent c7c2f30 commit f0c60a3

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2017 the original author or authors.
2+
* Copyright 2006-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java

+28
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import org.apache.commons.logging.Log;
2121
import org.apache.commons.logging.LogFactory;
2222
import org.junit.Before;
23+
import org.junit.Rule;
2324
import org.junit.Test;
25+
26+
import org.junit.rules.ExpectedException;
2427
import org.springframework.aop.framework.ProxyFactory;
2528
import org.springframework.batch.core.BatchStatus;
2629
import org.springframework.batch.core.ChunkListener;
@@ -76,6 +79,9 @@
7679
*/
7780
public class FaultTolerantStepFactoryBeanTests {
7881

82+
@Rule
83+
public ExpectedException expectedException = ExpectedException.none();
84+
7985
protected final Log logger = LogFactory.getLog(getClass());
8086

8187
private FaultTolerantStepFactoryBean<String, String> factory;
@@ -134,6 +140,28 @@ public void setUp() throws Exception {
134140
repository.add(stepExecution);
135141
}
136142

143+
@Test
144+
public void testMandatoryReader() throws Exception {
145+
factory = new FaultTolerantStepFactoryBean<>();
146+
factory.setItemWriter(writer);
147+
148+
expectedException.expect(IllegalStateException.class);
149+
expectedException.expectMessage("ItemReader must be provided");
150+
151+
factory.getObject();
152+
}
153+
154+
@Test
155+
public void testMandatoryWriter() throws Exception {
156+
factory = new FaultTolerantStepFactoryBean<>();
157+
factory.setItemReader(reader);
158+
159+
expectedException.expect(IllegalStateException.class);
160+
expectedException.expectMessage("ItemWriter must be provided");
161+
162+
factory.getObject();
163+
}
164+
137165
/**
138166
* Non-skippable (and non-fatal) exception causes failure immediately.
139167
*

spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2017 the original author or authors.
2+
* Copyright 2006-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,8 +27,9 @@
2727
import java.util.List;
2828

2929
import org.junit.Before;
30-
import org.junit.Ignore;
30+
import org.junit.Rule;
3131
import org.junit.Test;
32+
import org.junit.rules.ExpectedException;
3233
import org.springframework.batch.core.BatchStatus;
3334
import org.springframework.batch.core.ChunkListener;
3435
import org.springframework.batch.core.ItemProcessListener;
@@ -64,6 +65,9 @@
6465
*/
6566
public class SimpleStepFactoryBeanTests {
6667

68+
@Rule
69+
public ExpectedException expectedException = ExpectedException.none();
70+
6771
private List<Exception> listened = new ArrayList<Exception>();
6872

6973
private SimpleJobRepository repository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(),
@@ -78,7 +82,7 @@ public void write(List<? extends String> data) throws Exception {
7882
}
7983
};
8084

81-
private ItemReader<String> reader;
85+
private ItemReader<String> reader = new ListItemReader<>(Arrays.asList("a", "b", "c"));
8286

8387
private SimpleJob job = new SimpleJob();
8488

@@ -93,6 +97,28 @@ public void testMandatoryProperties() throws Exception {
9397
new SimpleStepFactoryBean<String, String>().getObject();
9498
}
9599

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+
96122
@Test
97123
public void testSimpleJob() throws Exception {
98124

0 commit comments

Comments
 (0)