diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListener.java index 5098ba3ff..9739b0884 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListener.java @@ -19,7 +19,6 @@ package org.springframework.batch.core.step; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.listener.StepExecutionListenerSupport; -import org.springframework.batch.item.NoWorkFoundException; /** * Fails the step if no items have been processed ( item count is 0). @@ -30,9 +29,9 @@ public class NoWorkFoundStepExecutionListener extends StepExecutionListenerSuppo public ExitStatus afterStep(StepExecution stepExecution) { if (stepExecution.getReadCount() == 0) { - throw new NoWorkFoundException("Step has not processed any items"); + return ExitStatus.FAILED; } - return stepExecution.getExitStatus(); + return null; } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListenerTests.java index 527e2fe58..b4d295a67 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListenerTests.java @@ -15,35 +15,43 @@ */ package org.springframework.batch.core.step; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.item.NoWorkFoundException; /** * Tests for {@link NoWorkFoundStepExecutionListener}. */ -public class NoWorkFoundStepExecutionListenerTests extends TestCase { +public class NoWorkFoundStepExecutionListenerTests { - private NoWorkFoundStepExecutionListener tested = new NoWorkFoundStepExecutionListener(); + private NoWorkFoundStepExecutionListener tested = new NoWorkFoundStepExecutionListener(); - /** - * If item count is zero exception is thrown - */ - public void testAfterStep() { - StepExecution stepExecution = new StepExecution("NoProcessingStep", - new JobExecution( - new JobInstance(1L, new JobParameters(), "NoProcessingJob"))); + @Test + public void noWork() { + StepExecution stepExecution = new StepExecution("NoProcessingStep", new JobExecution(new JobInstance(1L, + new JobParameters(), "NoProcessingJob"))); - stepExecution.setReadCount(0); + stepExecution.setExitStatus(ExitStatus.COMPLETED); + stepExecution.setReadCount(0); - try { - tested.afterStep(stepExecution); - fail(); - } catch (NoWorkFoundException e) { - assertEquals("Step has not processed any items", e.getMessage()); - } - } + ExitStatus exitStatus = tested.afterStep(stepExecution); + assertEquals(ExitStatus.FAILED.getExitCode(), exitStatus.getExitCode()); + } + + @Test + public void workDone() { + StepExecution stepExecution = new StepExecution("NoProcessingStep", new JobExecution(new JobInstance(1L, + new JobParameters(), "NoProcessingJob"))); + + stepExecution.setReadCount(1); + + ExitStatus exitStatus = tested.afterStep(stepExecution); + assertNull(exitStatus); + } } 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 1be22784f..55b39a146 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,6 +1,8 @@ package org.springframework.batch.core.step.item; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Arrays; @@ -31,7 +33,6 @@ import org.springframework.batch.core.repository.support.MapJobRepositoryFactory import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.item.NoWorkFoundException; import org.springframework.batch.item.ParseException; import org.springframework.batch.item.UnexpectedInputException; import org.springframework.batch.item.support.ListItemReader; @@ -730,7 +731,7 @@ public class FaultTolerantStepFactoryBeanTests { this.failures = failures; } - public String read() throws Exception, UnexpectedInputException, NoWorkFoundException, ParseException { + public String read() throws Exception, UnexpectedInputException, ParseException { counter++; if (counter >= items.length) { logger.debug("Returning null at count=" + counter); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/NoWorkFoundException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/NoWorkFoundException.java deleted file mode 100644 index 9bfc95e6f..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/NoWorkFoundException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2006-2008 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.item; - -/** - * Exception indicating no work was found - e.g. the input is empty or - * more generally no items were processed. - * - * @author Lucas Ward - * @author Ben Hale - */ -public class NoWorkFoundException extends ItemReaderException { - - /** - * Create a new {@link NoWorkFoundException} based on a message. - * - * @param message the message for this exception - */ - public NoWorkFoundException(String message) { - super(message); - } - - /** - * Create a new {@link NoWorkFoundException} based on a message and another exception. - * - * @param msg the message for this exception - * @param nested the other exception - */ - public NoWorkFoundException(String msg, Throwable nested) { - super(msg, nested); - } -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemReader.java index 0d9495356..c3b0e673f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemReader.java @@ -25,7 +25,6 @@ import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemStreamException; -import org.springframework.batch.item.NoWorkFoundException; import org.springframework.batch.item.ParseException; import org.springframework.batch.item.UnexpectedInputException; import org.springframework.batch.item.util.ExecutionContextUserSupport; @@ -81,7 +80,7 @@ public class MultiResourceItemReader implements ItemReader, ItemStream { /** * Reads the next item, jumping to next resource if necessary. */ - public T read() throws Exception, UnexpectedInputException, NoWorkFoundException, ParseException { + public T read() throws Exception, UnexpectedInputException, ParseException { if (noInput) { return null; diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/InfiniteLoopReader.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/InfiniteLoopReader.java index 95894990c..ff0a71ac1 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/InfiniteLoopReader.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/InfiniteLoopReader.java @@ -17,21 +17,19 @@ package org.springframework.batch.sample.common; import org.springframework.batch.item.ItemReader; -import org.springframework.batch.item.NoWorkFoundException; import org.springframework.batch.item.ParseException; import org.springframework.batch.item.UnexpectedInputException; /** - * ItemReader implementation that will continually return a new object. It's generally - * useful for testing interruption. + * ItemReader implementation that will continually return a new object. It's + * generally useful for testing interruption. * * @author Lucas Ward - * + * */ public class InfiniteLoopReader implements ItemReader { - public Object read() throws Exception, UnexpectedInputException, - NoWorkFoundException, ParseException { + public Object read() throws Exception, UnexpectedInputException, ParseException { return new Object(); }