public Tracking<DefaultIssue, DefaultIssue> track(Component component, Input<DefaultIssue> rawInput) {
    Input<DefaultIssue> openBaseIssuesInput = baseInputFactory.create(component);
    NonClosedTracking<DefaultIssue, DefaultIssue> openIssueTracking = tracker.trackNonClosed(rawInput, openBaseIssuesInput);
    if (openIssueTracking.isComplete() || analysisMetadataHolder.isFirstAnalysis()) {
      return openIssueTracking;
    }

    Input<DefaultIssue> closedIssuesBaseInput = closedIssuesInputFactory.create(component);
    Tracking<DefaultIssue, DefaultIssue> closedIssuesTracking = tracker.trackClosed(openIssueTracking, closedIssuesBaseInput);

    // changes of closed issues need to be loaded in order to:
    // - compute right transition from workflow
    // - recover fields values from before they were closed
    Set<DefaultIssue> matchesClosedIssues = closedIssuesTracking.getMatchedRaws().values().stream()
      .filter(t -> Issue.STATUS_CLOSED.equals(t.getStatus()))
      .collect(Collectors.toSet());
    componentIssuesLoader.loadLatestDiffChangesForReopeningOfClosedIssues(matchesClosedIssues);

    return closedIssuesTracking;
  }
@Test
  public void track_tracks_only_nonClosed_issues_if_tracking_returns_complete_from_Tracker() {
    ReportComponent component = ReportComponent.builder(Component.Type.FILE, 1).build();
    when(baseInputFactory.create(component)).thenReturn(openIssuesInput);
    when(closedIssuesInputFactory.create(any())).thenThrow(new IllegalStateException("closedIssuesInputFactory should not be called"));
    when(nonClosedTracking.isComplete()).thenReturn(true);
    when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
    when(tracker.trackNonClosed(rawInput, openIssuesInput)).thenReturn(nonClosedTracking);
    when(tracker.trackClosed(any(), any())).thenThrow(new IllegalStateException("trackClosed should not be called"));

    Tracking<DefaultIssue, DefaultIssue> tracking = underTest.track(component, rawInput);

    assertThat(tracking).isSameAs(nonClosedTracking);
    verify(tracker).trackNonClosed(rawInput, openIssuesInput);
    verifyNoMoreInteractions(tracker);
  }