]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1772:
authorGodin <mandrikov@gmail.com>
Tue, 19 Oct 2010 21:04:10 +0000 (21:04 +0000)
committerGodin <mandrikov@gmail.com>
Tue, 19 Oct 2010 21:04:10 +0000 (21:04 +0000)
* Don't use existing rules config
* Add more tests

plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsNativeSensor.java
plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsNativeSensorTest.java

index 08e9dcc865ee2fe00ea6299973a23962b785d30a..6bf24b8f0e94e238d643d6ab7bec87c0f50ffc49 100644 (file)
@@ -33,7 +33,7 @@ public class FindbugsNativeSensor implements Sensor {
 
   public boolean shouldExecuteOnProject(Project project) {
     return project.getFileSystem().hasJavaSourceFiles()
-        && ( !profile.getActiveRulesByRepository(FindbugsConstants.REPOSITORY_KEY).isEmpty() || project.getReuseExistingRulesConfig())
+        && !profile.getActiveRulesByRepository(FindbugsConstants.REPOSITORY_KEY).isEmpty()
         && project.getPom() != null && !StringUtils.equalsIgnoreCase(project.getPom().getPackaging(), "ear");
   }
 
index 8c5c37a8c1777dfcb15af2b470ec3b561404ad15..e07429aa93e03a7476fa3b3523299f2f3d71e176 100644 (file)
@@ -49,6 +49,34 @@ public class FindbugsNativeSensorTest extends FindbugsTests {
     assertFalse(analyser.shouldExecuteOnProject(project));
   }
 
+  @Test
+  public void shouldExecuteFindbugsWhenNoReportProvided() throws Exception {
+    Project project = createProject();
+    FindbugsExecutor executor = mock(FindbugsExecutor.class);
+    SensorContext context = mock(SensorContext.class);
+    Configuration conf = mock(Configuration.class);
+    File xmlFile = new File(getClass().getResource("/org/sonar/plugins/findbugs/findbugsXml.xml").toURI());
+    when(project.getConfiguration()).thenReturn(conf);
+    when(executor.execute()).thenReturn(xmlFile);
+    when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
+
+    FindbugsNativeSensor analyser = new FindbugsNativeSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), executor);
+    analyser.analyse(project, context);
+
+    verify(executor).execute();
+    verify(context, times(3)).saveViolation(any(Violation.class));
+
+    Violation wanted = new Violation(null, new JavaFile("org.sonar.commons.ZipUtils")).setMessage(
+        "Empty zip file entry created in org.sonar.commons.ZipUtils._zip(String, File, ZipOutputStream)").setLineId(107);
+
+    verify(context).saveViolation(argThat(new IsViolation(wanted)));
+
+    wanted = new Violation(null, new JavaFile("org.sonar.commons.resources.MeasuresDao")).setMessage(
+        "The class org.sonar.commons.resources.MeasuresDao$1 could be refactored into a named _static_ inner class").setLineId(56);
+
+    verify(context).saveViolation(argThat(new IsViolation(wanted)));
+  }
+
   @Test
   public void shouldReuseReport() throws Exception {
     Project project = createProject();