DeciderService { protected List<Task> filterNextLoopOverTasks(List<Task> tasks, Task pendingTask, Workflow workflow) { tasks.forEach(nextTask -> { nextTask.setReferenceTaskName(TaskUtils.appendIteration(nextTask.getReferenceTaskName(), pendingTask.getIteration())); nextTask.setIteration(pendingTask.getIteration());}); List<String> tasksInWorkflow = workflow.getTasks().stream() .filter(runningTask -> runningTask.getStatus().equals(Status.IN_PROGRESS) || runningTask.getStatus().isTerminal()) .map(Task::getReferenceTaskName) .collect(Collectors.toList()); return tasks.stream() .filter(runningTask -> !tasksInWorkflow.contains(runningTask.getReferenceTaskName())) .collect(Collectors.toList()); } @Inject  DeciderService(ParametersUtils parametersUtils, MetadataDAO metadataDAO,
                          ExternalPayloadStorageUtils externalPayloadStorageUtils,
                          @Named("TaskMappers") Map<String, TaskMapper> taskMappers, Configuration configuration); DeciderOutcome decide(Workflow workflow); List<Task> getTasksToBeScheduled(Workflow workflow,
                                            WorkflowTask taskToSchedule, int retryCount); List<Task> getTasksToBeScheduled(Workflow workflow,
                                            WorkflowTask taskToSchedule, int retryCount, String retriedTaskId);  }
@Test public void testFilterNextLoopOverTasks() { Workflow workflow = new Workflow(); Task task1 = new Task(); task1.setReferenceTaskName("task1"); task1.setStatus(Status.COMPLETED); task1.setTaskId("task1"); task1.setIteration(1); Task task2 = new Task(); task2.setReferenceTaskName("task2"); task2.setStatus(Status.SCHEDULED); task2.setTaskId("task2"); Task task3 = new Task(); task3.setReferenceTaskName("task3__1"); task3.setStatus(Status.IN_PROGRESS); task3.setTaskId("task3__1"); Task task4 = new Task(); task4.setReferenceTaskName("task4"); task4.setStatus(Status.SCHEDULED); task4.setTaskId("task4"); Task task5 = new Task(); task5.setReferenceTaskName("task5"); task5.setStatus(Status.COMPLETED); task5.setTaskId("task5"); workflow.getTasks().addAll(Arrays.asList(task1, task2, task3, task4, task5)); List<Task> tasks = deciderService.filterNextLoopOverTasks(Arrays.asList(task2, task3, task4), task1, workflow); assertEquals(2, tasks.size()); tasks.forEach(task -> { assertTrue(task.getReferenceTaskName().endsWith(TaskUtils.getLoopOverTaskRefNameSuffix(1))); assertEquals(1, task.getIteration()); }); }