]> source.dussan.org Git - sonarqube.git/blob
ee95ed5860414284b199c0ff3bc9d76f42053f28
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2020 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.server.organization;
21
22 import org.junit.Test;
23
24 import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.verifyZeroInteractions;
28 import static org.mockito.Mockito.when;
29 import static org.sonar.server.organization.BillingValidations.Organization;
30
31 public class BillingValidationsProxyImplTest {
32
33   private static final Organization ORGANIZATION = new Organization("ORGANIZATION_KEY", "ORGANIZATION_UUID", "ORGANIZATION_NAME");
34
35   private BillingValidationsExtension billingValidationsExtension = mock(BillingValidationsExtension.class);
36
37   private BillingValidationsProxyImpl underTest;
38
39   @Test
40   public void checkOnProjectAnalysis_calls_extension_when_available() {
41     underTest = new BillingValidationsProxyImpl(billingValidationsExtension);
42
43     underTest.checkBeforeProjectAnalysis(ORGANIZATION);
44
45     verify(billingValidationsExtension).checkBeforeProjectAnalysis(ORGANIZATION);
46   }
47
48   @Test
49   public void checkOnProjectAnalysis_does_nothing_when_no_extension_available() {
50     underTest = new BillingValidationsProxyImpl();
51
52     underTest.checkBeforeProjectAnalysis(ORGANIZATION);
53
54     verifyZeroInteractions(billingValidationsExtension);
55   }
56
57   @Test
58   public void checkCanUpdateProjectsVisibility_calls_extension_when_available() {
59     underTest = new BillingValidationsProxyImpl(billingValidationsExtension);
60
61     underTest.checkCanUpdateProjectVisibility(ORGANIZATION, true);
62
63     verify(billingValidationsExtension).checkCanUpdateProjectVisibility(ORGANIZATION, true);
64   }
65
66   @Test
67   public void checkCanUpdateProjectsVisibility_does_nothing_when_no_extension_available() {
68     underTest = new BillingValidationsProxyImpl();
69
70     underTest.checkCanUpdateProjectVisibility(ORGANIZATION, true);
71
72     verifyZeroInteractions(billingValidationsExtension);
73   }
74
75   @Test
76   public void canUpdateProjectsVisibilityToPrivate_calls_extension_when_available() {
77     underTest = new BillingValidationsProxyImpl(billingValidationsExtension);
78     when(billingValidationsExtension.canUpdateProjectVisibilityToPrivate(ORGANIZATION)).thenReturn(false);
79
80     boolean result = underTest.canUpdateProjectVisibilityToPrivate(ORGANIZATION);
81
82     assertThat(result).isFalse();
83     verify(billingValidationsExtension).canUpdateProjectVisibilityToPrivate(ORGANIZATION);
84   }
85
86   @Test
87   public void canUpdateProjectsVisibilityToPrivate_return_true_when_no_extension() {
88     underTest = new BillingValidationsProxyImpl();
89
90     boolean result = underTest.canUpdateProjectVisibilityToPrivate(ORGANIZATION);
91
92     assertThat(result).isTrue();
93     verifyZeroInteractions(billingValidationsExtension);
94   }
95
96 }