Search in sources :

Example 1 with Tracking

use of org.sonar.core.issue.tracking.Tracking in project sonarqube by SonarSource.

the class TrackerExecutionTest method track_loadChanges_on_matched_closed_issues.

@Test
public void track_loadChanges_on_matched_closed_issues() {
    ReportComponent component = ReportComponent.builder(Component.Type.FILE, 1).build();
    when(baseInputFactory.create(component)).thenReturn(openIssuesInput);
    when(closedIssuesInputFactory.create(component)).thenReturn(closedIssuesInput);
    when(nonClosedTracking.isComplete()).thenReturn(false);
    when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
    when(tracker.trackNonClosed(rawInput, openIssuesInput)).thenReturn(nonClosedTracking);
    when(tracker.trackClosed(nonClosedTracking, closedIssuesInput)).thenReturn(closedTracking);
    Set<DefaultIssue> mappedClosedIssues = IntStream.range(1, 2 + new Random().nextInt(2)).mapToObj(i -> new DefaultIssue().setKey("closed" + i).setStatus(Issue.STATUS_CLOSED)).collect(toSet());
    ArrayList<DefaultIssue> mappedBaseIssues = new ArrayList<>(mappedClosedIssues);
    Issue.STATUSES.stream().filter(t -> !Issue.STATUS_CLOSED.equals(t)).forEach(s -> mappedBaseIssues.add(new DefaultIssue().setKey(s).setStatus(s)));
    Collections.shuffle(mappedBaseIssues);
    when(closedTracking.getMatchedRaws()).thenReturn(mappedBaseIssues.stream().collect(uniqueIndex(i -> new DefaultIssue().setKey("raw_for_" + i.key()), i -> i)));
    Tracking<DefaultIssue, DefaultIssue> tracking = underTest.track(component, rawInput);
    assertThat(tracking).isSameAs(closedTracking);
    verify(tracker).trackNonClosed(rawInput, openIssuesInput);
    verify(tracker).trackClosed(nonClosedTracking, closedIssuesInput);
    verify(componentIssuesLoader).loadLatestDiffChangesForReopeningOfClosedIssues(mappedClosedIssues);
    verifyNoMoreInteractions(tracker);
}
Also used : IntStream(java.util.stream.IntStream) Component(org.sonar.ce.task.projectanalysis.component.Component) NonClosedTracking(org.sonar.core.issue.tracking.NonClosedTracking) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DefaultIssue(org.sonar.core.issue.DefaultIssue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Tracking(org.sonar.core.issue.tracking.Tracking) Random(java.util.Random) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ArrayList(java.util.ArrayList) AnalysisMetadataHolder(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder) Input(org.sonar.core.issue.tracking.Input) Mockito.verify(org.mockito.Mockito.verify) Issue(org.sonar.api.issue.Issue) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Tracker(org.sonar.core.issue.tracking.Tracker) Collections(java.util.Collections) Collectors.toSet(java.util.stream.Collectors.toSet) Mockito.mock(org.mockito.Mockito.mock) Random(java.util.Random) ArrayList(java.util.ArrayList) DefaultIssue(org.sonar.core.issue.DefaultIssue) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Random (java.util.Random)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IntStream (java.util.stream.IntStream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)1 Mockito.when (org.mockito.Mockito.when)1 Issue (org.sonar.api.issue.Issue)1 AnalysisMetadataHolder (org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder)1 Component (org.sonar.ce.task.projectanalysis.component.Component)1 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)1 DefaultIssue (org.sonar.core.issue.DefaultIssue)1 Input (org.sonar.core.issue.tracking.Input)1 NonClosedTracking (org.sonar.core.issue.tracking.NonClosedTracking)1