File tree Expand file tree Collapse file tree 2 files changed +7
-8
lines changed
main/java/io/serverlessworkflow/utils
test/java/io/serverlessworkflow/util Expand file tree Collapse file tree 2 files changed +7
-8
lines changed Original file line number Diff line number Diff line change 1818import io .serverlessworkflow .api .Workflow ;
1919import io .serverlessworkflow .api .interfaces .State ;
2020import io .serverlessworkflow .api .start .Start ;
21- import java .util .Objects ;
2221
2322/** Provides common utility methods to provide most often needed answers from a workflow */
2423public final class WorkflowUtils {
25-
24+ private static int DEFAULT_STATE = 0 ;
2625 /**
27- * Gets State matching Start state name If start is not present returns first state Returns null
28- * otherwise
26+ * Gets State matching Start state. If start is not present returns first state otherwise Returns
27+ * null
2928 *
3029 * @param workflow workflow
3130 * @return {@code state} when present else returns {@code null}
3231 */
3332 public static State getStartingState (Workflow workflow ) {
34- Objects .requireNonNull (workflow );
35- if (workflow .getStates () == null || workflow .getStates ().isEmpty ()) {
33+ if (workflow == null || workflow .getStates () == null || workflow .getStates ().isEmpty ()) {
3634 return null ;
3735 }
3836
3937 Start start = workflow .getStart ();
4038 if (start == null ) {
41- return workflow .getStates ().stream (). findFirst (). get ();
39+ return workflow .getStates ().get (DEFAULT_STATE );
4240 } else {
4341 return workflow .getStates ().stream ()
4442 .filter (state -> state .getName ().equals (start .getStateName ()))
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ public void testGetStartStateForWorkflowWithNoState(String workflowWithNoState)
5757
5858 @ Test
5959 public void testGetStateForNullWorkflow () {
60- assertThrows (NullPointerException .class , () -> WorkflowUtils .getStartingState (null ));
60+ State startingState = WorkflowUtils .getStartingState (null );
61+ assertNull (startingState );
6162 }
6263}
You can’t perform that action at this time.
0 commit comments