3 * Copyright (C) 2009-2020 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.organization;
22 import org.junit.Test;
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;
31 public class BillingValidationsProxyImplTest {
33 private static final Organization ORGANIZATION = new Organization("ORGANIZATION_KEY", "ORGANIZATION_UUID", "ORGANIZATION_NAME");
35 private BillingValidationsExtension billingValidationsExtension = mock(BillingValidationsExtension.class);
37 private BillingValidationsProxyImpl underTest;
40 public void checkOnProjectAnalysis_calls_extension_when_available() {
41 underTest = new BillingValidationsProxyImpl(billingValidationsExtension);
43 underTest.checkBeforeProjectAnalysis(ORGANIZATION);
45 verify(billingValidationsExtension).checkBeforeProjectAnalysis(ORGANIZATION);
49 public void checkOnProjectAnalysis_does_nothing_when_no_extension_available() {
50 underTest = new BillingValidationsProxyImpl();
52 underTest.checkBeforeProjectAnalysis(ORGANIZATION);
54 verifyZeroInteractions(billingValidationsExtension);
58 public void checkCanUpdateProjectsVisibility_calls_extension_when_available() {
59 underTest = new BillingValidationsProxyImpl(billingValidationsExtension);
61 underTest.checkCanUpdateProjectVisibility(ORGANIZATION, true);
63 verify(billingValidationsExtension).checkCanUpdateProjectVisibility(ORGANIZATION, true);
67 public void checkCanUpdateProjectsVisibility_does_nothing_when_no_extension_available() {
68 underTest = new BillingValidationsProxyImpl();
70 underTest.checkCanUpdateProjectVisibility(ORGANIZATION, true);
72 verifyZeroInteractions(billingValidationsExtension);
76 public void canUpdateProjectsVisibilityToPrivate_calls_extension_when_available() {
77 underTest = new BillingValidationsProxyImpl(billingValidationsExtension);
78 when(billingValidationsExtension.canUpdateProjectVisibilityToPrivate(ORGANIZATION)).thenReturn(false);
80 boolean result = underTest.canUpdateProjectVisibilityToPrivate(ORGANIZATION);
82 assertThat(result).isFalse();
83 verify(billingValidationsExtension).canUpdateProjectVisibilityToPrivate(ORGANIZATION);
87 public void canUpdateProjectsVisibilityToPrivate_return_true_when_no_extension() {
88 underTest = new BillingValidationsProxyImpl();
90 boolean result = underTest.canUpdateProjectVisibilityToPrivate(ORGANIZATION);
92 assertThat(result).isTrue();
93 verifyZeroInteractions(billingValidationsExtension);