@VisibleForTesting
  void initializeForeachArtifactRollup(
      ForeachStepOverview foreachOverview,
      ForeachStepOverview prevForeachOverview,
      String foreachWorkflowId) {
    Set<Long> iterationsToRunInNewRun =
        foreachOverview.getIterationsToRunFromDetails(prevForeachOverview);
    WorkflowRollupOverview aggregatedRollupsPrevRun =
        getAggregatedRollupFromIterations(foreachWorkflowId, iterationsToRunInNewRun);

    foreachOverview.initiateStepRollup(prevForeachOverview.getRollup(), aggregatedRollupsPrevRun);
  }
@Test
  public void testInitializeForeachArtifactRollup() throws IOException {
    ForeachStepOverview curr =
        loadObject(
            "fixtures/instances/sample-foreach-step-overview.json", ForeachStepOverview.class);

    ForeachStepOverview prev =
        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();
    curr.setRollup(null);

    WorkflowRollupOverview.CountReference ref = new WorkflowRollupOverview.CountReference();
    ref.setCnt(10);
    WorkflowRollupOverview.CountReference ref2 = new WorkflowRollupOverview.CountReference();
    ref2.setCnt(2);
    WorkflowRollupOverview rollup = new WorkflowRollupOverview();
    rollup.setTotalLeafCount(12);
    EnumMap<StepInstance.Status, WorkflowRollupOverview.CountReference> overview =
        new EnumMap<>(StepInstance.Status.class);
    overview.put(StepInstance.Status.SUCCEEDED, ref);
    overview.put(StepInstance.Status.FATALLY_FAILED, ref2);
    rollup.setOverview(overview);

    prev.setRollup(rollup);

    List<WorkflowRollupOverview> rollups = new ArrayList<>();
    ref = new WorkflowRollupOverview.CountReference();
    ref.setCnt(1);
    rollup = new WorkflowRollupOverview();
    rollup.setTotalLeafCount(1);
    rollup.setOverview(singletonEnumMap(StepInstance.Status.FATALLY_FAILED, ref));
    rollups.add(rollup);
    rollups.add(rollup);

    doReturn(rollups)
        .when(workflowInstanceDao)
        .getBatchForeachLatestRunRollupForIterations(eq("workflowid"), any());
    foreachStepRuntime.initializeForeachArtifactRollup(curr, prev, "workflowid");
    assertEquals(10, curr.getRollup().getTotalLeafCount());
    assertEquals(10, curr.getRollup().getOverview().get(StepInstance.Status.SUCCEEDED).getCnt());
  }