]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2213 Cobertura: initializer should set correct report path
authorEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 1 Mar 2011 12:30:03 +0000 (15:30 +0300)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 1 Mar 2011 13:27:32 +0000 (16:27 +0300)
plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaMavenInitializer.java
plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaMavenInitializerTest.java

index 6452a08a0cd924f0cfd80b68eba809daf325ab6f..822427c469a35bb91e930715e4d8d8fc00b5d52c 100644 (file)
@@ -57,7 +57,7 @@ public class CoberturaMavenInitializer extends Initializer implements CoverageEx
   @Override
   public void execute(Project project) {
     Configuration conf = project.getConfiguration();
-    if (conf.containsKey(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY)) {
+    if (!conf.containsKey(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY)) {
       String report = getReportPathFromPluginConfiguration(project);
       if (report == null) {
         report = getDefaultReportPath(project);
index 0c252abdfef0ad9507dbb0ac287ab55db158dab6..7ac644c530ca6cb48715340b2c30a75ba88c90ae 100644 (file)
  */
 package org.sonar.plugins.cobertura;
 
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.resources.Project;
-
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.Matchers.nullValue;
 import static org.hamcrest.core.IsNot.not;
 import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import org.apache.commons.configuration.Configuration;
+import org.apache.maven.project.MavenProject;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.resources.Project;
+import org.sonar.api.test.MavenTestUtils;
+
 public class CoberturaMavenInitializerTest {
 
   private Project project;
@@ -60,4 +68,22 @@ public class CoberturaMavenInitializerTest {
     assertThat(initializer.getMavenPluginHandler(project).getArtifactId(), is("cobertura-maven-plugin"));
   }
 
+  @Test
+  public void doNotSetReportPathIfAlreadyConfigured() {
+    Configuration configuration = mock(Configuration.class);
+    when(configuration.containsKey(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY)).thenReturn(true);
+    when(project.getConfiguration()).thenReturn(configuration);
+    initializer.execute(project);
+    verify(configuration, never()).setProperty(eq(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY), anyString());
+  }
+
+  @Test
+  public void shouldSetReportPathFromPom() {
+    Configuration configuration = mock(Configuration.class);
+    when(project.getConfiguration()).thenReturn(configuration);
+    MavenProject pom = MavenTestUtils.loadPom("/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldGetReportPathFromPom/pom.xml");
+    when(project.getPom()).thenReturn(pom);
+    initializer.execute(project);
+    verify(configuration).setProperty(eq(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY), eq("overridden/dir/coverage.xml"));
+  }
 }