BATCH-1053: Updated javadocs to explain the behavior of getStep and getState if the step/state is not found.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 + "]");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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"))));
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user