]> source.dussan.org Git - sonarqube.git/blob
4588e4fd52f503aae230c5370273d8bbdff3f5f0
[sonarqube.git] /
1 package org.sonar.plugins.cobertura.api;
2
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;
7
8 import org.apache.maven.project.MavenProject;
9 import org.junit.Test;
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;
14
15 import java.io.File;
16 import java.net.URISyntaxException;
17
18 public class CoberturaUtilsTest {
19   @Test
20   public void shouldGetReportPathFromProperty() throws URISyntaxException {
21     DefaultProjectFileSystem fileSystem = mock(DefaultProjectFileSystem.class);
22     when(fileSystem.resolvePath("foo")).thenReturn(getCoverageReport());
23
24     Project project = mock(Project.class);
25     when(project.getFileSystem()).thenReturn(fileSystem);
26     when(project.getProperty(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY)).thenReturn("foo");
27
28     File report = CoberturaUtils.getReport(project);
29     verify(fileSystem).resolvePath("foo");
30     assertNotNull(report);
31   }
32
33   @Test
34   public void shouldGetReportPathFromPom() {
35     MavenProject pom = MavenTestUtils.loadPom("/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldGetReportPathFromPom/pom.xml");
36
37     DefaultProjectFileSystem fileSystem = mock(DefaultProjectFileSystem.class);
38
39     Project project = mock(Project.class);
40     when(project.getPom()).thenReturn(pom);
41     when(project.getFileSystem()).thenReturn(fileSystem);
42
43     CoberturaUtils.getReport(project);
44
45     verify(fileSystem).resolvePath("overridden/dir");
46   }
47
48   private File getCoverageReport() throws URISyntaxException {
49     return new File(getClass().getResource("/org/sonar/plugins/cobertura/CoberturaSensorTest/commons-chain-coverage.xml").toURI());
50   }
51 }