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 org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.Mock;
30 import org.mockito.MockitoAnnotations;
31 import org.sonar.db.component.BranchType;
32 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
33 import org.sonar.server.computation.task.projectanalysis.analysis.Branch;
34 import org.sonar.server.computation.task.projectanalysis.component.Component;
36 public class IssueTrackingDelegatorTest {
38 private ShortBranchTrackerExecution shortBranchTracker;
40 private TrackerExecution tracker;
42 private AnalysisMetadataHolder analysisMetadataHolder;
44 private Component component;
46 private IssueTrackingDelegator underTest;
50 MockitoAnnotations.initMocks(this);
51 underTest = new IssueTrackingDelegator(shortBranchTracker, tracker, analysisMetadataHolder);
55 public void delegate_regular_tracker() {
56 when(analysisMetadataHolder.isShortLivingBranch()).thenReturn(false);
58 underTest.track(component);
60 verify(tracker).track(component);
61 verifyZeroInteractions(shortBranchTracker);
65 public void delegate_short_branch_tracker() {
66 Branch branch = mock(Branch.class);
67 when(branch.getType()).thenReturn(BranchType.SHORT);
68 when(analysisMetadataHolder.isShortLivingBranch()).thenReturn(true);
70 underTest.track(component);
72 verify(shortBranchTracker).track(component);
73 verifyZeroInteractions(tracker);