2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2008-2012 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * Sonar 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 * Sonar 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
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.plugins.findbugs;
22 import org.apache.commons.io.FileUtils;
23 import org.junit.Before;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.TemporaryFolder;
27 import org.sonar.api.CoreProperties;
28 import org.sonar.api.config.PropertyDefinitions;
29 import org.sonar.api.config.Settings;
30 import org.sonar.api.profiles.RulesProfile;
31 import org.sonar.api.resources.Project;
32 import org.sonar.api.test.SimpleProjectFileSystem;
35 import java.util.Locale;
37 import static org.fest.assertions.Assertions.assertThat;
38 import static org.mockito.Mockito.mock;
39 import static org.mockito.Mockito.when;
41 public class FindbugsConfigurationTest {
44 public TemporaryFolder tempFolder = new TemporaryFolder();
46 private Project project;
47 private Settings settings;
48 private File findbugsTempDir;
49 private FindbugsConfiguration conf;
53 project = mock(Project.class);
54 settings = new Settings(new PropertyDefinitions().addComponent(FindbugsPlugin.class));
55 findbugsTempDir = tempFolder.newFolder("findbugs");
56 when(project.getFileSystem()).thenReturn(new SimpleProjectFileSystem(findbugsTempDir));
57 conf = new FindbugsConfiguration(project, settings, RulesProfile.create(), new FindbugsProfileExporter(), null);
61 public void should_return_report_file() throws Exception {
62 assertThat(conf.getTargetXMLReport()).isEqualTo(new File(findbugsTempDir, "target/sonar/findbugs-result.xml"));
66 public void should_save_include_config() throws Exception {
67 conf.saveIncludeConfigXml();
68 File findbugsIncludeFile = new File(findbugsTempDir + "/target/sonar/findbugs-include.xml");
69 assertThat(findbugsIncludeFile.exists()).isTrue();
73 public void should_save_exclude_config() throws Exception {
74 when(project.getExclusionPatterns()).thenReturn(new String[] {"dir/**/*.java"});
75 conf.saveExcludeConfigXml();
76 File findbugsExcludeFile = new File(findbugsTempDir + "/target/sonar/findbugs-exclude.xml");
77 assertThat(findbugsExcludeFile.exists()).isTrue();
78 String findbugsExclude = FileUtils.readFileToString(findbugsExcludeFile);
79 assertThat(findbugsExclude).contains("Match");
83 public void should_save_empty_exclude_config() throws Exception {
84 conf.saveExcludeConfigXml();
85 File findbugsExcludeFile = new File(findbugsTempDir + "/target/sonar/findbugs-exclude.xml");
86 assertThat(findbugsExcludeFile.exists()).isTrue();
87 String findbugsExclude = FileUtils.readFileToString(findbugsExcludeFile);
88 assertThat(findbugsExclude).doesNotContain("Match");
92 public void should_return_effort() {
93 assertThat(conf.getEffort()).as("default effort").isEqualTo("default");
94 settings.setProperty(CoreProperties.FINDBUGS_EFFORT_PROPERTY, "Max");
95 assertThat(conf.getEffort()).isEqualTo("max");
99 public void should_return_timeout() {
100 assertThat(conf.getTimeout()).as("default timeout").isEqualTo(600000);
101 settings.setProperty(CoreProperties.FINDBUGS_TIMEOUT_PROPERTY, 1);
102 assertThat(conf.getTimeout()).isEqualTo(1);
106 public void should_return_locale() {
107 settings.setProperty(CoreProperties.CORE_VIOLATION_LOCALE_PROPERTY, "fr");
108 assertThat(conf.getLocale()).isEqualTo(Locale.FRENCH);
112 public void should_return_excludes_filters() {
113 assertThat(conf.getExcludesFilters()).isEmpty();
114 settings.setProperty(FindbugsConstants.EXCLUDES_FILTERS_PROPERTY, " foo.xml , bar.xml,");
115 assertThat(conf.getExcludesFilters()).hasSize(2);
119 public void should_return_confidence_level() {
120 assertThat(conf.getConfidenceLevel()).as("default confidence level").isEqualTo("medium");
121 settings.setProperty(CoreProperties.FINDBUGS_EFFORT_PROPERTY, "HIGH");
122 assertThat(conf.getEffort()).isEqualTo("high");