Skip to content

Commit 231e8bb

Browse files
committed
Added GetNumOfEndStates util method #127
Signed-off-by: manick02 <[email protected]>
1 parent 2ae111e commit 231e8bb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ public static long getNumOfStates(Workflow workflow, DefaultState.Type type) {
290290
: DEFAULT_STATE_COUNT;
291291
}
292292

293+
public static long getNumOfEndStates(Workflow workflow) {
294+
return hasStates(workflow)
295+
? workflow.getStates().stream().filter(state -> state.getEnd() != null).count()
296+
: DEFAULT_STATE_COUNT;
297+
}
298+
293299
private static List<Action> getActionsWhichUsesFunctionDefinition(
294300
Workflow workflow, String functionDefinitionName) {
295301
List<Action> actions = new ArrayList<>();

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,12 @@ public void testGetNumStatesOfEventType(String workflowWithStates) {
5050
assertEquals(
5151
expectedStatesCount, WorkflowUtils.getNumOfStates(workflow, DefaultState.Type.EVENT));
5252
}
53+
54+
@ParameterizedTest
55+
@ValueSource(strings = {"/events/workflowwithevents.yml"})
56+
public void testGetNumEndStates(String workflowWithStates) {
57+
Workflow workflow = TestUtils.createWorkflowFromTestResource(workflowWithStates);
58+
int expectedEndStatesCount = 2;
59+
assertEquals(expectedEndStatesCount, WorkflowUtils.getNumOfEndStates(workflow));
60+
}
5361
}

0 commit comments

Comments
 (0)