]> source.dussan.org Git - sonarqube.git/blob
224e94c1f370283fd7c8a0801693da2778d91c1e
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2022 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.ce.task.projectanalysis.step;
21
22 import org.junit.Test;
23 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
24 import org.sonar.ce.task.projectanalysis.view.TriggerViewRefreshDelegate;
25 import org.sonar.ce.task.step.TestComputationStepContext;
26 import org.sonar.server.project.Project;
27
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.verifyZeroInteractions;
31 import static org.mockito.Mockito.when;
32
33 public class TriggerViewRefreshStepTest {
34   private AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
35
36   @Test
37   public void execute_has_no_effect_if_constructor_without_delegate() {
38     TriggerViewRefreshStep underTest = new TriggerViewRefreshStep(analysisMetadataHolder);
39
40     underTest.execute(new TestComputationStepContext());
41
42     verifyZeroInteractions(analysisMetadataHolder);
43   }
44
45   @Test
46   public void execute_has_no_effect_if_constructor_with_null_delegate() {
47     TriggerViewRefreshStep underTest = new TriggerViewRefreshStep(analysisMetadataHolder);
48
49     underTest.execute(new TestComputationStepContext());
50
51     verifyZeroInteractions(analysisMetadataHolder);
52   }
53
54   @Test
55   public void execute_calls_delegate_with_project_from_holder_if_passed_to_constructor() {
56     TriggerViewRefreshDelegate delegate = mock(TriggerViewRefreshDelegate.class);
57     Project project = mock(Project.class);
58     when(analysisMetadataHolder.getProject()).thenReturn(project);
59     TriggerViewRefreshStep underTest = new TriggerViewRefreshStep(analysisMetadataHolder, new TriggerViewRefreshDelegate[]{delegate});
60
61     underTest.execute(new TestComputationStepContext());
62
63     verify(analysisMetadataHolder).getProject();
64     verify(delegate).triggerFrom(project);
65   }
66 }