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 18
18
import io .serverlessworkflow .api .Workflow ;
19
19
import io .serverlessworkflow .api .interfaces .State ;
20
20
import io .serverlessworkflow .api .start .Start ;
21
- import java .util .Objects ;
22
21
23
22
/** Provides common utility methods to provide most often needed answers from a workflow */
24
23
public final class WorkflowUtils {
25
-
24
+ private static int DEFAULT_STATE = 0 ;
26
25
/**
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
29
28
*
30
29
* @param workflow workflow
31
30
* @return {@code state} when present else returns {@code null}
32
31
*/
33
32
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 ()) {
36
34
return null ;
37
35
}
38
36
39
37
Start start = workflow .getStart ();
40
38
if (start == null ) {
41
- return workflow .getStates ().stream (). findFirst (). get ();
39
+ return workflow .getStates ().get (DEFAULT_STATE );
42
40
} else {
43
41
return workflow .getStates ().stream ()
44
42
.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)
57
57
58
58
@ Test
59
59
public void testGetStateForNullWorkflow () {
60
- assertThrows (NullPointerException .class , () -> WorkflowUtils .getStartingState (null ));
60
+ State startingState = WorkflowUtils .getStartingState (null );
61
+ assertNull (startingState );
61
62
}
62
63
}
You can’t perform that action at this time.
0 commit comments