Browse Source

SONAR-1772: Add FindbugsNativeSensorTest

tags/2.6
Godin 13 years ago
parent
commit
9edb39c091

+ 5
- 5
plugins/sonar-findbugs-plugin/pom.xml View File

@@ -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>

+ 49
- 0
plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsNativeSensorTest.java View File

@@ -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;
}

}

Loading…
Cancel
Save