diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java index efc919f37..39ec0cddc 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java @@ -126,7 +126,8 @@ public abstract class AbstractJob implements Job, BeanNameAware, InitializingBea } /** - * Retrieve the step with the given name + * Retrieve the step with the given name. An IllegalStateException is thrown + * if there is no Step with the given name. * * @param stepName * @return the step diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/Flow.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/Flow.java index ffb8723a2..fe77e0cfd 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/Flow.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/Flow.java @@ -29,8 +29,11 @@ public interface Flow { String getName(); /** + * Retrieve the State with the given name. An IllegalStateException is + * thrown if there is no State with the given name. + * * @param stateName - * @return the State in the flow with given name + * @return the State */ public State getState(String stateName); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java index 613a6c02c..bae06462a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java @@ -65,8 +65,10 @@ public class FlowJob extends AbstractJob { */ public Step getStep(String stepName){ State state = this.flow.getState(stepName); - Assert.isInstanceOf(StepState.class, state, "State is not a StepState: [" + stepName + "]"); - return ((StepState) state).getStep(); + if(state instanceof StepState){ + return ((StepState) state).getStep(); + } + throw new IllegalStateException("State is not a StepState: [" + stepName + "]"); } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/SimpleFlow.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/SimpleFlow.java index 5e738dfe7..46fda44d9 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/SimpleFlow.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/SimpleFlow.java @@ -30,7 +30,6 @@ import org.springframework.batch.core.job.flow.FlowExecution; import org.springframework.batch.core.job.flow.FlowExecutionException; import org.springframework.batch.core.job.flow.FlowExecutor; import org.springframework.beans.factory.InitializingBean; -import org.springframework.util.Assert; /** * A {@link Flow} that branches conditionally depending on the exit status of @@ -88,7 +87,9 @@ public class SimpleFlow implements Flow, InitializingBean { */ public State getState(String stateName) { State state = stateMap.get(stateName); - Assert.notNull(state, "No State found with name: [" + stateName + "]"); + if(state == null){ + throw new IllegalStateException("No State found with name: [" + stateName + "]"); + } return state; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/support/SimpleFlowTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/support/SimpleFlowTests.java index 44586c77f..fbce6be67 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/support/SimpleFlowTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/support/SimpleFlowTests.java @@ -215,7 +215,7 @@ public class SimpleFlowTests { assertEquals("step1", state.getName()); } - @Test(expected = IllegalArgumentException.class) + @Test(expected = IllegalStateException.class) public void testGetStateDoesNotExist() throws Exception { flow.setStateTransitions(Collections.singletonList(StateTransition.createEndStateTransition(new StubState( "step1")))); diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/AbstractJobTests.java b/spring-batch-test/src/main/java/org/springframework/batch/test/AbstractJobTests.java index c1a7350c0..2ce7b9c3b 100644 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/AbstractJobTests.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/AbstractJobTests.java @@ -138,19 +138,13 @@ public abstract class AbstractJobTests { } /** - * Launch just the specified step in the job. + * Launch just the specified step in the job. An IllegalStateException is thrown + * if there is no Step with the given name. * * @param stepName */ public JobExecution launchStep(String stepName) { - Step step; - try { - step = this.job.getStep(stepName); - } - catch (IllegalArgumentException e) { - throw new IllegalStateException("No Step found with name: [" + stepName + "]", e); - } - return getStepRunner().launchStep(step); + return getStepRunner().launchStep(this.job.getStep(stepName)); } /**