diff options
-rw-r--r-- | plugins/sonar-findbugs-plugin/pom.xml | 10 | ||||
-rw-r--r-- | plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsNativeSensorTest.java | 49 |
2 files changed, 54 insertions, 5 deletions
diff --git a/plugins/sonar-findbugs-plugin/pom.xml b/plugins/sonar-findbugs-plugin/pom.xml index 2f6587ba895..509b963193e 100644 --- a/plugins/sonar-findbugs-plugin/pom.xml +++ b/plugins/sonar-findbugs-plugin/pom.xml @@ -17,6 +17,11 @@ <findbugs.version>1.3.9</findbugs.version> </properties> + <!-- IMPORTANT! + xalan should be excluded everywhere, because contains Apache BCEL, + but FindBugs requires its own version of BCEL - see http://findbugs.sourceforge.net/FAQ.html#q2 + --> + <dependencyManagement> <!-- Change versions for dependencies provided by sonar-plugin-api --> <dependencies> @@ -25,11 +30,6 @@ <artifactId>xercesImpl</artifactId> <version>2.6.2</version> </dependency> - <!--dependency> - <groupId>xalan</groupId> - <artifactId>xalan</artifactId> - <version>2.6.0</version> - </dependency--> </dependencies> </dependencyManagement> diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsNativeSensorTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsNativeSensorTest.java new file mode 100644 index 00000000000..4530003378f --- /dev/null +++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsNativeSensorTest.java @@ -0,0 +1,49 @@ +package org.sonar.plugins.findbugs; + +import org.apache.maven.project.MavenProject; +import org.junit.Test; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.resources.DefaultProjectFileSystem; +import org.sonar.api.resources.Project; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class FindbugsNativeSensorTest extends FindbugsTests { + + @Test + public void shouldExecuteWhenSomeRulesAreActive() throws Exception { + FindbugsSensor sensor = new FindbugsSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), null); + Project project = createProject(); + assertTrue(sensor.shouldExecuteOnProject(project)); + } + + @Test + public void shouldNotExecuteWhenNoRulesAreActive() throws Exception { + FindbugsSensor analyser = new FindbugsSensor(RulesProfile.create(), new FindbugsRuleFinder(), null); + Project pom = createProject(); + assertFalse(analyser.shouldExecuteOnProject(pom)); + } + + @Test + public void shouldNotExecuteOnEar() { + Project project = createProject(); + when(project.getPom().getPackaging()).thenReturn("ear"); + FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), null); + assertFalse(analyser.shouldExecuteOnProject(project)); + } + + private Project createProject() { + DefaultProjectFileSystem fileSystem = mock(DefaultProjectFileSystem.class); + when(fileSystem.hasJavaSourceFiles()).thenReturn(Boolean.TRUE); + + MavenProject mavenProject = mock(MavenProject.class); + Project project = mock(Project.class); + when(project.getFileSystem()).thenReturn(fileSystem); + when(project.getPom()).thenReturn(mavenProject); + return project; + } + +} |