3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.computation.task.projectanalysis.issue;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.verify;
24 import static org.mockito.Mockito.verifyZeroInteractions;
25 import static org.mockito.Mockito.when;
27 import java.util.Optional;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mock;
32 import org.mockito.MockitoAnnotations;
33 import org.sonar.core.issue.DefaultIssue;
34 import org.sonar.core.issue.tracking.Tracking;
35 import org.sonar.db.component.BranchType;
36 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
37 import org.sonar.server.computation.task.projectanalysis.analysis.Branch;
38 import org.sonar.server.computation.task.projectanalysis.component.Component;
40 public class IssueTrackingDelegatorTest {
42 private ShortBranchTrackerExecution shortBranchTracker;
44 private MergeBranchTrackerExecution mergeBranchTracker;
46 private TrackerExecution tracker;
48 private AnalysisMetadataHolder analysisMetadataHolder;
50 private Component component;
52 private Tracking<DefaultIssue, DefaultIssue> trackingResult;
54 private IssueTrackingDelegator underTest;
58 MockitoAnnotations.initMocks(this);
59 underTest = new IssueTrackingDelegator(shortBranchTracker, mergeBranchTracker, tracker, analysisMetadataHolder);
60 when(tracker.track(component)).thenReturn(trackingResult);
61 when(mergeBranchTracker.track(component)).thenReturn(trackingResult);
62 when(shortBranchTracker.track(component)).thenReturn(trackingResult);
66 public void delegate_regular_tracker() {
67 when(analysisMetadataHolder.isShortLivingBranch()).thenReturn(false);
68 when(analysisMetadataHolder.getBranch()).thenReturn(Optional.empty());
70 underTest.track(component);
72 verify(tracker).track(component);
73 verifyZeroInteractions(shortBranchTracker);
74 verifyZeroInteractions(mergeBranchTracker);
78 public void delegate_merge_tracker() {
79 Branch branch = mock(Branch.class);
80 when(branch.getType()).thenReturn(BranchType.LONG);
81 when(branch.isMain()).thenReturn(false);
82 when(analysisMetadataHolder.getBranch()).thenReturn(Optional.of(branch));
83 when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(true);
85 underTest.track(component);
87 verify(mergeBranchTracker).track(component);
88 verifyZeroInteractions(tracker);
89 verifyZeroInteractions(shortBranchTracker);
94 public void delegate_short_branch_tracker() {
95 Branch branch = mock(Branch.class);
96 when(branch.getType()).thenReturn(BranchType.SHORT);
97 when(analysisMetadataHolder.getBranch()).thenReturn(Optional.empty());
98 when(analysisMetadataHolder.isShortLivingBranch()).thenReturn(true);
100 underTest.track(component);
102 verify(shortBranchTracker).track(component);
103 verifyZeroInteractions(tracker);
104 verifyZeroInteractions(mergeBranchTracker);