1 package org.sonar.plugins.cobertura.api;
3 import static org.junit.Assert.assertNotNull;
4 import static org.mockito.Mockito.mock;
5 import static org.mockito.Mockito.verify;
6 import static org.mockito.Mockito.when;
8 import org.apache.maven.project.MavenProject;
10 import org.sonar.api.CoreProperties;
11 import org.sonar.api.resources.DefaultProjectFileSystem;
12 import org.sonar.api.resources.Project;
13 import org.sonar.api.test.MavenTestUtils;
16 import java.net.URISyntaxException;
18 public class CoberturaUtilsTest {
20 public void shouldGetReportPathFromProperty() throws URISyntaxException {
21 DefaultProjectFileSystem fileSystem = mock(DefaultProjectFileSystem.class);
22 when(fileSystem.resolvePath("foo")).thenReturn(getCoverageReport());
24 Project project = mock(Project.class);
25 when(project.getFileSystem()).thenReturn(fileSystem);
26 when(project.getProperty(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY)).thenReturn("foo");
28 File report = CoberturaUtils.getReport(project);
29 verify(fileSystem).resolvePath("foo");
30 assertNotNull(report);
34 public void shouldGetReportPathFromPom() {
35 MavenProject pom = MavenTestUtils.loadPom("/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldGetReportPathFromPom/pom.xml");
37 DefaultProjectFileSystem fileSystem = mock(DefaultProjectFileSystem.class);
39 Project project = mock(Project.class);
40 when(project.getPom()).thenReturn(pom);
41 when(project.getFileSystem()).thenReturn(fileSystem);
43 CoberturaUtils.getReport(project);
45 verify(fileSystem).resolvePath("overridden/dir");
48 private File getCoverageReport() throws URISyntaxException {
49 return new File(getClass().getResource("/org/sonar/plugins/cobertura/CoberturaSensorTest/commons-chain-coverage.xml").toURI());