3 * Copyright (C) 2009-2023 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.scanner.scan;
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;
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.CREDENTIALS_WARN_MESSAGE;
38 public class DeprecatedPropertiesWarningGeneratorTest {
41 public LogTester logger = new LogTester();
43 private final MapSettings settings = new MapSettings();
45 private final AnalysisWarnings analysisWarnings = Mockito.spy(AnalysisWarnings.class);
46 private final DeprecatedPropertiesWarningGenerator underTest = new DeprecatedPropertiesWarningGenerator(settings.asConfig(),
50 public void setUp() throws Exception {
51 settings.removeProperty(CoreProperties.LOGIN);
52 settings.removeProperty(CoreProperties.PASSWORD);
56 public void execute_whenUsingLogin_shouldAddWarning() {
57 settings.setProperty(CoreProperties.LOGIN, "test");
61 verify(analysisWarnings, times(1)).addUnique(CREDENTIALS_WARN_MESSAGE);
62 Assertions.assertThat(logger.logs(LoggerLevel.WARN)).contains(CREDENTIALS_WARN_MESSAGE);
66 public void execute_whenUsingPassword_shouldAddWarning() {
67 settings.setProperty(CoreProperties.PASSWORD, "winner winner chicken dinner");
71 verify(analysisWarnings, times(1)).addUnique(CREDENTIALS_WARN_MESSAGE);
72 Assertions.assertThat(logger.logs(LoggerLevel.WARN)).contains(CREDENTIALS_WARN_MESSAGE);
76 public void execute_whenNotUsingLoginOrPassword_shouldNotAddWarning() {
79 verifyNoInteractions(analysisWarnings);
80 Assertions.assertThat(logger.logs(LoggerLevel.WARN)).isEmpty();