summaryrefslogtreecommitdiffstats
path: root/plugins/sonar-cobertura-plugin
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-03-01 15:30:03 +0300
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-03-01 16:27:32 +0300
commit2a57b977752e0d651d023cee0b4deb2dce57b38e (patch)
treea27f210d06dc326f12f9ef05383da61dbe9f8d3b /plugins/sonar-cobertura-plugin
parent41bdddbdb38337c3758242cd64e6e93a4c710338 (diff)
downloadsonarqube-2a57b977752e0d651d023cee0b4deb2dce57b38e.tar.gz
sonarqube-2a57b977752e0d651d023cee0b4deb2dce57b38e.zip
SONAR-2213 Cobertura: initializer should set correct report path
Diffstat (limited to 'plugins/sonar-cobertura-plugin')
-rw-r--r--plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaMavenInitializer.java2
-rw-r--r--plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaMavenInitializerTest.java34
2 files changed, 31 insertions, 5 deletions
diff --git a/plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaMavenInitializer.java b/plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaMavenInitializer.java
index 6452a08a0cd..822427c469a 100644
--- a/plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaMavenInitializer.java
+++ b/plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaMavenInitializer.java
@@ -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);
diff --git a/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaMavenInitializerTest.java b/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaMavenInitializerTest.java
index 0c252abdfef..7ac644c530c 100644
--- a/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaMavenInitializerTest.java
+++ b/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaMavenInitializerTest.java
@@ -19,17 +19,25 @@
*/
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"));
+ }
}