diff options
author | Julien HENRY <henryju@yahoo.fr> | 2016-07-05 17:05:34 +0200 |
---|---|---|
committer | Julien HENRY <henryju@yahoo.fr> | 2016-07-06 09:32:40 +0200 |
commit | 99aa7e8a80ba86da975059a59295c07666240d4a (patch) | |
tree | 81052e633ba73621e54a895893308a4d35d7ec16 /sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java | |
parent | 6da2fd6aea26d9d29c3d3f39419e000009be9c14 (diff) | |
download | sonarqube-99aa7e8a80ba86da975059a59295c07666240d4a.tar.gz sonarqube-99aa7e8a80ba86da975059a59295c07666240d4a.zip |
Rename package org.sonar.batch to org.sonar.scanner
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java')
-rw-r--r-- | sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java new file mode 100644 index 00000000000..00c9ea3d8dd --- /dev/null +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java @@ -0,0 +1,104 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.scanner.rule; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.rules.TemporaryFolder; +import org.slf4j.Logger; +import org.sonar.api.batch.fs.internal.DefaultFileSystem; +import org.sonar.api.config.Settings; +import org.sonar.api.utils.MessageException; +import org.sonar.scanner.rule.ModuleQProfiles; +import org.sonar.scanner.rule.QProfile; +import org.sonar.scanner.rule.QProfileVerifier; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class QProfileVerifierTest { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private DefaultFileSystem fs; + private ModuleQProfiles profiles; + private Settings settings = new Settings(); + + @Before + public void before() throws Exception { + fs = new DefaultFileSystem(temp.newFolder().toPath()); + profiles = mock(ModuleQProfiles.class); + QProfile javaProfile = new QProfile().setKey("p1").setName("My Java profile").setLanguage("java"); + when(profiles.findByLanguage("java")).thenReturn(javaProfile); + QProfile cobolProfile = new QProfile().setKey("p2").setName("My Cobol profile").setLanguage("cobol"); + when(profiles.findByLanguage("cobol")).thenReturn(cobolProfile); + } + + @Test + public void should_log_all_used_profiles() { + fs.addLanguages("java", "cobol"); + QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles); + Logger logger = mock(Logger.class); + profileLogger.execute(logger); + + verify(logger).info("Quality profile for {}: {}", "java", "My Java profile"); + verify(logger).info("Quality profile for {}: {}", "cobol", "My Cobol profile"); + } + + @Test + public void should_fail_if_default_profile_not_used() { + fs.addLanguages("java", "cobol"); + settings.setProperty("sonar.profile", "Unknown"); + + QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles); + + thrown.expect(MessageException.class); + thrown.expectMessage("sonar.profile was set to 'Unknown' but didn't match any profile for any language. Please check your configuration."); + + profileLogger.execute(); + } + + @Test + public void should_not_fail_if_no_language_on_project() { + settings.setProperty("sonar.profile", "Unknown"); + + QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles); + + profileLogger.execute(); + + } + + @Test + public void should_not_fail_if_default_profile_used_at_least_once() { + fs.addLanguages("java", "cobol"); + settings.setProperty("sonar.profile", "My Java profile"); + + QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles); + + profileLogger.execute(); + } +} |