public Set<Long> getIterationsToRunFromDetails(ForeachStepOverview prevStepOverview) {
    if (prevStepOverview == null || prevStepOverview.details == null) {
      return new HashSet<>();
    }
    Set<Long> currRunInstances =
        details == null
            ? new HashSet<>()
            : details.flatten(e -> true).values().stream()
                .flatMap(List::stream)
                .collect(Collectors.toSet());
    return prevStepOverview.details.flatten(e -> true).values().stream()
        .flatMap(List::stream)
        .filter(e -> !currRunInstances.contains(e))
        .collect(Collectors.toSet());
  }
@Test
  public void testGetIterationsToRunFromDetails() throws Exception {
    ForeachStepOverview prev =
        loadObject(
            "fixtures/instances/sample-foreach-step-overview.json", ForeachStepOverview.class);

    ForeachStepOverview curr =
        loadObject(
            "fixtures/instances/sample-foreach-step-overview.json", ForeachStepOverview.class);

    curr.getDetails().getInfo().remove(WorkflowInstance.Status.IN_PROGRESS);
    curr.getDetails().getInfo().remove(WorkflowInstance.Status.SUCCEEDED);
    curr.addOne(80110, WorkflowInstance.Status.SUCCEEDED, new WorkflowRollupOverview());
    curr.addOne(80115, WorkflowInstance.Status.SUCCEEDED, new WorkflowRollupOverview());
    curr.refreshDetail();

    List<Long> flattenedSuccPrevDetails =
        prev.getDetails().flatten(e -> true).get(WorkflowInstance.Status.SUCCEEDED);

    assertEquals(5, flattenedSuccPrevDetails.size());
    assertEquals(
        1, prev.getDetails().flatten(e -> true).get(WorkflowInstance.Status.IN_PROGRESS).size());
    assertTrue(flattenedSuccPrevDetails.contains(80110L));
    assertTrue(flattenedSuccPrevDetails.contains(80115L));
    assertTrue(flattenedSuccPrevDetails.contains(80112L));
    assertTrue(flattenedSuccPrevDetails.contains(80113L));
    assertTrue(flattenedSuccPrevDetails.contains(80114L));
    assertTrue(
        prev.getDetails()
            .flatten(e -> true)
            .get(WorkflowInstance.Status.IN_PROGRESS)
            .contains(70000L));

    Set<Long> result = curr.getIterationsToRunFromDetails(prev);
    assertEquals(4, result.size());
    assertFalse(result.contains(80110L));
    assertFalse(result.contains(80115L));

    ForeachStepOverview newOne = new ForeachStepOverview();
    result = newOne.getIterationsToRunFromDetails(prev);
    assertEquals(6, result.size());

    result = newOne.getIterationsToRunFromDetails(null);
    assertEquals(0, result.size());

    result = newOne.getIterationsToRunFromDetails(new ForeachStepOverview());
    assertEquals(0, result.size());

    result = prev.getIterationsToRunFromDetails(new ForeachStepOverview());
    assertEquals(0, result.size());
  }