3 * Copyright (C) 2009-2019 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.ce.task.projectanalysis.issue;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.mockito.Mock;
25 import org.mockito.MockitoAnnotations;
26 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
27 import org.sonar.ce.task.projectanalysis.analysis.Branch;
28 import org.sonar.ce.task.projectanalysis.component.Component;
29 import org.sonar.core.issue.DefaultIssue;
30 import org.sonar.core.issue.tracking.Tracking;
31 import org.sonar.db.component.BranchType;
33 import static org.mockito.Mockito.mock;
34 import static org.mockito.Mockito.verify;
35 import static org.mockito.Mockito.verifyZeroInteractions;
36 import static org.mockito.Mockito.when;
38 public class IssueTrackingDelegatorTest {
40 private ShortBranchOrPullRequestTrackerExecution shortBranchTracker;
42 private MergeBranchTrackerExecution mergeBranchTracker;
44 private TrackerExecution tracker;
46 private AnalysisMetadataHolder analysisMetadataHolder;
48 private Component component;
50 private Tracking<DefaultIssue, DefaultIssue> trackingResult;
52 private IssueTrackingDelegator underTest;
56 MockitoAnnotations.initMocks(this);
57 underTest = new IssueTrackingDelegator(shortBranchTracker, mergeBranchTracker, tracker, analysisMetadataHolder);
58 when(tracker.track(component)).thenReturn(trackingResult);
59 when(mergeBranchTracker.track(component)).thenReturn(trackingResult);
60 when(shortBranchTracker.track(component)).thenReturn(trackingResult);
64 public void delegate_regular_tracker() {
65 when(analysisMetadataHolder.isShortLivingBranch()).thenReturn(false);
66 when(analysisMetadataHolder.getBranch()).thenReturn(mock(Branch.class));
68 underTest.track(component);
70 verify(tracker).track(component);
71 verifyZeroInteractions(shortBranchTracker);
72 verifyZeroInteractions(mergeBranchTracker);
76 public void delegate_merge_tracker() {
77 Branch branch = mock(Branch.class);
78 when(branch.getType()).thenReturn(BranchType.LONG);
79 when(branch.isMain()).thenReturn(false);
80 when(analysisMetadataHolder.getBranch()).thenReturn(branch);
81 when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(true);
83 underTest.track(component);
85 verify(mergeBranchTracker).track(component);
86 verifyZeroInteractions(tracker);
87 verifyZeroInteractions(shortBranchTracker);
92 public void delegate_short_branch_tracker() {
93 Branch branch = mock(Branch.class);
94 when(branch.getType()).thenReturn(BranchType.SHORT);
95 when(analysisMetadataHolder.getBranch()).thenReturn(mock(Branch.class));
96 when(analysisMetadataHolder.isShortLivingBranch()).thenReturn(true);
98 underTest.track(component);
100 verify(shortBranchTracker).track(component);
101 verifyZeroInteractions(tracker);
102 verifyZeroInteractions(mergeBranchTracker);
106 public void delegate_pull_request_tracker() {
107 Branch branch = mock(Branch.class);
108 when(branch.getType()).thenReturn(BranchType.PULL_REQUEST);
109 when(analysisMetadataHolder.getBranch()).thenReturn(mock(Branch.class));
110 when(analysisMetadataHolder.isShortLivingBranch()).thenReturn(true);
112 underTest.track(component);
114 verify(shortBranchTracker).track(component);
115 verifyZeroInteractions(tracker);
116 verifyZeroInteractions(mergeBranchTracker);