aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2012-07-09 14:07:06 +0600
committerEvgeny Mandrikov <mandrikov@gmail.com>2012-07-09 14:07:06 +0600
commite77eee8680e0d4089e40cd461e7355b6f52e82f3 (patch)
treec4cfd69efb63abaebec846a1b58d180ef2f6dfb0
parentd8805a9ab69c8c65906a404f89504c407316abef (diff)
downloadsonarqube-e77eee8680e0d4089e40cd461e7355b6f52e82f3.tar.gz
sonarqube-e77eee8680e0d4089e40cd461e7355b6f52e82f3.zip
Improve coverage of FindbugsConfiguration
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java10
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java51
2 files changed, 50 insertions, 11 deletions
diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java
index a71516c92f6..10de177c4d9 100644
--- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java
+++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java
@@ -19,6 +19,7 @@
*/
package org.sonar.plugins.findbugs;
+import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
@@ -83,13 +84,15 @@ public class FindbugsConfiguration implements BatchExtension {
return findbugsProject;
}
- public File saveIncludeConfigXml() throws IOException {
+ @VisibleForTesting
+ File saveIncludeConfigXml() throws IOException {
StringWriter conf = new StringWriter();
exporter.exportProfile(profile, conf);
return project.getFileSystem().writeToWorkingDirectory(conf.toString(), "findbugs-include.xml");
}
- public File saveExcludeConfigXml() throws IOException {
+ @VisibleForTesting
+ File saveExcludeConfigXml() throws IOException {
FindBugsFilter findBugsFilter = new FindBugsFilter();
if (project.getExclusionPatterns() != null) {
for (String exclusion : project.getExclusionPatterns()) {
@@ -100,7 +103,8 @@ public class FindbugsConfiguration implements BatchExtension {
return project.getFileSystem().writeToWorkingDirectory(findBugsFilter.toXml(), "findbugs-exclude.xml");
}
- public List<File> getExcludesFilters() {
+ @VisibleForTesting
+ List<File> getExcludesFilters() {
List<File> result = new ArrayList<File>();
String[] filters = settings.getStringArray(FindbugsConstants.EXCLUDES_FILTERS_PROPERTY);
for (String excludesFilterPath : filters) {
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java
index 0465c58174d..10073c87003 100644
--- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java
@@ -19,10 +19,13 @@
*/
package org.sonar.plugins.findbugs;
+import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
@@ -42,32 +45,64 @@ public class FindbugsConfigurationTest {
private Project project;
private Settings settings;
private File findbugsTempDir;
+ private FindbugsConfiguration conf;
@Before
- public void setup() {
+ public void setUp() {
project = mock(Project.class);
- settings = new Settings();
+ settings = new Settings(new PropertyDefinitions().addComponent(FindbugsPlugin.class));
findbugsTempDir = tempFolder.newFolder("findbugs");
when(project.getFileSystem()).thenReturn(new SimpleProjectFileSystem(findbugsTempDir));
+ conf = new FindbugsConfiguration(project, settings, RulesProfile.create(), new FindbugsProfileExporter(), null);
}
@Test
- public void shouldSaveConfigFiles() throws Exception {
- FindbugsConfiguration conf = new FindbugsConfiguration(project, settings, RulesProfile.create(), new FindbugsProfileExporter(), null);
+ public void should_return_report_file() throws Exception {
+ assertThat(conf.getTargetXMLReport()).isEqualTo(new File(findbugsTempDir, "target/sonar/findbugs-result.xml"));
+ }
+ @Test
+ public void should_save_include_config() throws Exception {
conf.saveIncludeConfigXml();
+ File findbugsIncludeFile = new File(findbugsTempDir + "/target/sonar/findbugs-include.xml");
+ assertThat(findbugsIncludeFile.exists()).isTrue();
+ }
+
+ @Test
+ public void should_save_exclude_config() throws Exception {
+ when(project.getExclusionPatterns()).thenReturn(new String[] {"dir/**/*.java"});
conf.saveExcludeConfigXml();
+ File findbugsExcludeFile = new File(findbugsTempDir + "/target/sonar/findbugs-exclude.xml");
+ assertThat(findbugsExcludeFile.exists()).isTrue();
+ String findbugsExclude = FileUtils.readFileToString(findbugsExcludeFile);
+ assertThat(findbugsExclude).contains("Match");
+ }
- File findbugsIncludeFile = new File(findbugsTempDir + "/target/sonar/findbugs-include.xml");
+ @Test
+ public void should_save_empty_exclude_config() throws Exception {
+ conf.saveExcludeConfigXml();
File findbugsExcludeFile = new File(findbugsTempDir + "/target/sonar/findbugs-exclude.xml");
- assertThat(findbugsIncludeFile.exists()).isTrue();
assertThat(findbugsExcludeFile.exists()).isTrue();
+ String findbugsExclude = FileUtils.readFileToString(findbugsExcludeFile);
+ assertThat(findbugsExclude).doesNotContain("Match");
}
@Test
- public void shouldReturnExcludesFilters() {
- FindbugsConfiguration conf = new FindbugsConfiguration(project, settings, RulesProfile.create(), new FindbugsProfileExporter(), null);
+ public void should_return_effort() {
+ assertThat(conf.getEffort()).as("default effort").isEqualTo("default");
+ settings.setProperty(CoreProperties.FINDBUGS_EFFORT_PROPERTY, "Max");
+ assertThat(conf.getEffort()).isEqualTo("max");
+ }
+ @Test
+ public void should_return_timeout() {
+ assertThat(conf.getTimeout()).as("default timeout").isEqualTo(600000);
+ settings.setProperty(CoreProperties.FINDBUGS_TIMEOUT_PROPERTY, 1);
+ assertThat(conf.getTimeout()).isEqualTo(1);
+ }
+
+ @Test
+ public void should_return_excludes_filters() {
assertThat(conf.getExcludesFilters()).isEmpty();
settings.setProperty(FindbugsConstants.EXCLUDES_FILTERS_PROPERTY, " foo.xml , bar.xml,");
assertThat(conf.getExcludesFilters()).hasSize(2);