]> source.dussan.org Git - sonarqube.git/blob
c6eb658e6f5919640f92f864ab641d999f8c9bd9
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2023 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.scanner.scan;
21
22 import org.assertj.core.api.Assertions;
23 import org.junit.Before;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.sonar.api.CoreProperties;
28 import org.sonar.api.config.internal.MapSettings;
29 import org.sonar.api.notifications.AnalysisWarnings;
30 import org.sonar.api.utils.log.LogTester;
31 import org.sonar.api.utils.log.LoggerLevel;
32
33 import static org.mockito.Mockito.times;
34 import static org.mockito.Mockito.verify;
35 import static org.mockito.Mockito.verifyNoInteractions;
36 import static org.sonar.scanner.scan.DeprecatedPropertiesWarningGenerator.LOGIN_WARN_MESSAGE;
37 import static org.sonar.scanner.scan.DeprecatedPropertiesWarningGenerator.PASSWORD_WARN_MESSAGE;
38
39 public class DeprecatedPropertiesWarningGeneratorTest {
40
41   @Rule
42   public LogTester logger = new LogTester();
43
44   private final MapSettings settings = new MapSettings();
45
46   private final AnalysisWarnings analysisWarnings = Mockito.spy(AnalysisWarnings.class);
47   private final DeprecatedPropertiesWarningGenerator underTest = new DeprecatedPropertiesWarningGenerator(settings.asConfig(),
48     analysisWarnings);
49
50   @Before
51   public void setUp() throws Exception {
52     settings.removeProperty(CoreProperties.LOGIN);
53     settings.removeProperty(CoreProperties.PASSWORD);
54   }
55
56   @Test
57   public void execute_whenUsingLogin_shouldAddWarning() {
58     settings.setProperty(CoreProperties.LOGIN, "test");
59
60     underTest.execute();
61
62     verify(analysisWarnings, times(1)).addUnique(LOGIN_WARN_MESSAGE);
63     Assertions.assertThat(logger.logs(LoggerLevel.WARN)).contains(LOGIN_WARN_MESSAGE);
64   }
65
66   @Test
67   public void execute_whenUsingPassword_shouldAddWarning() {
68     settings.setProperty(CoreProperties.LOGIN, "test");
69     settings.setProperty(CoreProperties.PASSWORD, "winner winner chicken dinner");
70
71     underTest.execute();
72
73     verify(analysisWarnings, times(1)).addUnique(PASSWORD_WARN_MESSAGE);
74     Assertions.assertThat(logger.logs(LoggerLevel.WARN)).contains(PASSWORD_WARN_MESSAGE);
75   }
76
77   @Test
78   public void execute_whenNotUsingLoginOrPassword_shouldNotAddWarning() {
79     underTest.execute();
80
81     verifyNoInteractions(analysisWarnings);
82     Assertions.assertThat(logger.logs(LoggerLevel.WARN)).isEmpty();
83   }
84
85 }