RESOLVED - BATCH-414: consistent handling of empty input by ItemReaders

renamed listener + reused NoWorkFoundException
This commit is contained in:
robokaso
2008-06-30 08:16:52 +00:00
parent b95f14075e
commit a35ad43fe7
3 changed files with 9 additions and 12 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.batch.core.step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
import org.springframework.batch.item.NoWorkFoundException;
import org.springframework.batch.repeat.ExitStatus;
/**
@@ -25,19 +26,13 @@ import org.springframework.batch.repeat.ExitStatus;
*
* @author Robert Kasanicky
*/
public class NoItemsProcessedDetector extends StepExecutionListenerSupport {
public class NoWorkFoundListener extends StepExecutionListenerSupport {
public ExitStatus afterStep(StepExecution stepExecution) {
if (stepExecution.getItemCount().intValue() == 0) {
throw new NoItemsProcessedException("Step has not processed any items");
throw new NoWorkFoundException("Step has not processed any items");
}
return stepExecution.getExitStatus();
}
private static class NoItemsProcessedException extends RuntimeException {
public NoItemsProcessedException(String message) {
super(message);
}
}
}

View File

@@ -20,10 +20,11 @@ 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;
public class NoItemsProcessedDetectorTests extends TestCase {
public class NoWorkFoundListenerTests extends TestCase {
private NoItemsProcessedDetector tested = new NoItemsProcessedDetector();
private NoWorkFoundListener tested = new NoWorkFoundListener();
/**
* If item count is zero exception is thrown
@@ -38,7 +39,7 @@ public class NoItemsProcessedDetectorTests extends TestCase {
try {
tested.afterStep(stepExecution);
fail();
} catch (RuntimeException e) {
} catch (NoWorkFoundException e) {
assertEquals("Step has not processed any items", e.getMessage());
}
}

View File

@@ -16,7 +16,8 @@
package org.springframework.batch.item;
/**
* Exception indicating that an {@link ItemReader} found no work to process while initializing.
* 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