BATCH-1125: Modified NoWorkFoundStepExecutionListener so that it will fail the step. Removed unused NoWorkFoundException.

This commit is contained in:
dhgarrette
2009-03-06 23:51:53 +00:00
parent dee9420cda
commit 78c88afce0
6 changed files with 38 additions and 78 deletions

View File

@@ -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);
}
}

View File

@@ -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);