Skip to content

Commit c2c62e4

Browse files
committed
Fix code review comments
- Return null when workflow is null - Comment fix - Simplify return default start state Signed-off-by: cb-manick <[email protected]>
1 parent 698cf69 commit c2c62e4

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

utils/src/main/java/io/serverlessworkflow/utils/WorkflowUtils.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,25 @@
1818
import io.serverlessworkflow.api.Workflow;
1919
import io.serverlessworkflow.api.interfaces.State;
2020
import 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 */
2423
public 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()))

utils/src/test/java/io/serverlessworkflow/util/StartStateTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)