diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java index ca2a8ee43..0cc69f8cc 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2017 the original author or authors. + * Copyright 2006-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java index 4e8b12d58..fc9928e8a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2017 the original author or authors. + * Copyright 2008-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,10 @@ import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.springframework.aop.framework.ProxyFactory; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ChunkListener; @@ -77,6 +79,9 @@ import static org.junit.Assert.assertTrue; */ public class FaultTolerantStepFactoryBeanTests { + @Rule + public ExpectedException expectedException = ExpectedException.none(); + protected final Log logger = LogFactory.getLog(getClass()); private FaultTolerantStepFactoryBean factory; @@ -135,6 +140,28 @@ public class FaultTolerantStepFactoryBeanTests { repository.add(stepExecution); } + @Test + public void testMandatoryReader() throws Exception { + factory = new FaultTolerantStepFactoryBean<>(); + factory.setItemWriter(writer); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("ItemReader must be provided"); + + factory.getObject(); + } + + @Test + public void testMandatoryWriter() throws Exception { + factory = new FaultTolerantStepFactoryBean<>(); + factory.setItemReader(reader); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("ItemWriter must be provided"); + + factory.getObject(); + } + /** * Non-skippable (and non-fatal) exception causes failure immediately. * diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java index 46e241771..a62ed6f0b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2017 the original author or authors. + * Copyright 2006-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,9 @@ import java.util.Collections; import java.util.List; import org.junit.Before; -import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ChunkListener; import org.springframework.batch.core.ItemProcessListener; @@ -64,6 +65,9 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor; */ public class SimpleStepFactoryBeanTests { + @Rule + public ExpectedException expectedException = ExpectedException.none(); + private List listened = new ArrayList(); private SimpleJobRepository repository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(), @@ -78,7 +82,7 @@ public class SimpleStepFactoryBeanTests { } }; - private ItemReader reader; + private ItemReader reader = new ListItemReader<>(Arrays.asList("a", "b", "c")); private SimpleJob job = new SimpleJob(); @@ -93,6 +97,28 @@ public class SimpleStepFactoryBeanTests { new SimpleStepFactoryBean().getObject(); } + @Test + public void testMandatoryReader() throws Exception { + SimpleStepFactoryBean factory = new SimpleStepFactoryBean<>(); + factory.setItemWriter(writer); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("ItemReader must be provided"); + + factory.getObject(); + } + + @Test + public void testMandatoryWriter() throws Exception { + SimpleStepFactoryBean factory = new SimpleStepFactoryBean<>(); + factory.setItemReader(reader); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("ItemWriter must be provided"); + + factory.getObject(); + } + @Test public void testSimpleJob() throws Exception {