From 2a57b977752e0d651d023cee0b4deb2dce57b38e Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Tue, 1 Mar 2011 15:30:03 +0300 Subject: [PATCH] SONAR-2213 Cobertura: initializer should set correct report path --- .../cobertura/CoberturaMavenInitializer.java | 2 +- .../CoberturaMavenInitializerTest.java | 34 ++++++++++++++++--- 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")); + } } -- 2.39.5