diff options
author | David Gageot <david@gageot.net> | 2012-07-13 14:19:10 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-07-13 14:29:35 +0200 |
commit | 9a9ea30f8be59e3289c9cebfc18cf40489a79adf (patch) | |
tree | f901ca7b8b18c52bfe956efd49cf1316eb0feacd /plugins | |
parent | 0bd84ea0219e949135ba488fc6b4a9b46030449b (diff) | |
download | sonarqube-9a9ea30f8be59e3289c9cebfc18cf40489a79adf.tar.gz sonarqube-9a9ea30f8be59e3289c9cebfc18cf40489a79adf.zip |
Make sure these tests work on Eclipse even with mvm eclipse:eclipse
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/sonar-jacoco-plugin/infinitest.filters | 4 | ||||
-rw-r--r-- | plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoItSensorTest.java | 52 | ||||
-rw-r--r-- | plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoSensorTest.java | 71 | ||||
-rw-r--r-- | plugins/sonar-jacoco-plugin/src/test/resources/Hello.class.toCopy (renamed from plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoSensorTest/Hello.class) | bin | 531 -> 531 bytes |
4 files changed, 76 insertions, 51 deletions
diff --git a/plugins/sonar-jacoco-plugin/infinitest.filters b/plugins/sonar-jacoco-plugin/infinitest.filters deleted file mode 100644 index dfc9c555025..00000000000 --- a/plugins/sonar-jacoco-plugin/infinitest.filters +++ /dev/null @@ -1,4 +0,0 @@ -# These tests fail in Eclipse. Until they are fixed, let's ignore them - -.*JaCoCoItSensorTest -.*JaCoCoSensorTest diff --git a/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoItSensorTest.java b/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoItSensorTest.java index a6aafb0570f..950fdae7cfe 100644 --- a/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoItSensorTest.java +++ b/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoItSensorTest.java @@ -19,7 +19,9 @@ */ package org.sonar.plugins.jacoco; +import com.google.common.io.Files; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.sonar.api.batch.SensorContext; import org.sonar.api.measures.CoreMetrics; @@ -30,8 +32,10 @@ import org.sonar.api.resources.Project.AnalysisType; import org.sonar.api.resources.ProjectFileSystem; import org.sonar.api.resources.Resource; import org.sonar.api.test.IsMeasure; +import org.sonar.test.TestUtils; import java.io.File; +import java.io.IOException; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -39,12 +43,27 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; public class JaCoCoItSensorTest { + private static File outputDir; + private static File jacocoExecutionData; + private JacocoConfiguration configuration; private JaCoCoItSensor sensor; + @BeforeClass + public static void setUpOutputDir() throws IOException { + outputDir = TestUtils.getResource("/org/sonar/plugins/jacoco/JaCoCoSensorTest/"); + jacocoExecutionData = new File(outputDir, "jacoco.exec"); + + Files.copy(TestUtils.getResource("Hello.class.toCopy"), new File(jacocoExecutionData.getParentFile(), "Hello.class")); + } + @Before public void setUp() { configuration = mock(JacocoConfiguration.class); @@ -58,34 +77,31 @@ public class JaCoCoItSensorTest { @Test public void doNotExecuteWhenReportPathNotSpecified() { - when(configuration.getItReportPath()).thenReturn(""); Project project = mock(Project.class); + when(configuration.getItReportPath()).thenReturn(""); + assertThat(sensor.shouldExecuteOnProject(project), is(false)); } @Test public void shouldExecuteOnProject() { - when(configuration.getItReportPath()).thenReturn("target/it-jacoco.exec"); Project project = mock(Project.class); + when(configuration.getItReportPath()).thenReturn("target/it-jacoco.exec"); when(project.getAnalysisType()).thenReturn(AnalysisType.DYNAMIC).thenReturn(AnalysisType.REUSE_REPORTS); + assertThat(sensor.shouldExecuteOnProject(project), is(true)); assertThat(sensor.shouldExecuteOnProject(project), is(true)); } @Test - public void testReadExecutionData() throws Exception { - File jacocoExecutionData = new File(getClass().getResource("/org/sonar/plugins/jacoco/JaCoCoSensorTest/jacoco.exec").getFile()); - File buildOutputDir = jacocoExecutionData.getParentFile(); + public void testReadExecutionData() { + JavaFile resource = new JavaFile("org.sonar.plugins.jacoco.tests.Hello"); SensorContext context = mock(SensorContext.class); - - final JavaFile resource = new JavaFile("org.sonar.plugins.jacoco.tests.Hello"); - when(context.getResource(any(Resource.class))).thenReturn(resource); - ProjectFileSystem pfs = mock(ProjectFileSystem.class); - when(pfs.getBuildOutputDir()).thenReturn(buildOutputDir); - when(pfs.resolvePath(anyString())).thenReturn(jacocoExecutionData); - Project project = mock(Project.class); + when(context.getResource(any(Resource.class))).thenReturn(resource); + when(pfs.getBuildOutputDir()).thenReturn(outputDir); + when(pfs.resolvePath(anyString())).thenReturn(jacocoExecutionData); when(project.getFileSystem()).thenReturn(pfs); sensor.analyse(project, context); @@ -103,16 +119,12 @@ public class JaCoCoItSensorTest { } @Test - public void doNotSaveMeasureOnResourceWhichDoesntExistInTheContext() throws Exception { - File jacocoExecutionData = new File(getClass().getResource("/org/sonar/plugins/jacoco/JaCoCoSensorTest/jacoco.exec").getFile()); - File buildOutputDir = jacocoExecutionData.getParentFile(); + public void doNotSaveMeasureOnResourceWhichDoesntExistInTheContext() { SensorContext context = mock(SensorContext.class); - when(context.getResource(any(Resource.class))).thenReturn(null); - ProjectFileSystem pfs = mock(ProjectFileSystem.class); - when(pfs.getBuildOutputDir()).thenReturn(buildOutputDir); - Project project = mock(Project.class); + when(context.getResource(any(Resource.class))).thenReturn(null); + when(pfs.getBuildOutputDir()).thenReturn(outputDir); when(project.getFileSystem()).thenReturn(pfs); sensor.analyse(project, context); diff --git a/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoSensorTest.java b/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoSensorTest.java index 36e6a0eafc7..7cb8879b232 100644 --- a/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoSensorTest.java +++ b/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoSensorTest.java @@ -19,32 +19,55 @@ */ package org.sonar.plugins.jacoco; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; - +import com.google.common.io.Files; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.sonar.api.batch.SensorContext; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; -import org.sonar.api.resources.*; +import org.sonar.api.resources.Java; +import org.sonar.api.resources.JavaFile; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.ProjectFileSystem; +import org.sonar.api.resources.Resource; import org.sonar.api.test.IsMeasure; +import org.sonar.test.TestUtils; import java.io.File; +import java.io.IOException; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.argThat; +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.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; /** * @author Evgeny Mandrikov */ public class JaCoCoSensorTest { + private static File jacocoExecutionData; + private static File outputDir; + private JacocoConfiguration configuration; private JaCoCoSensor sensor; + @BeforeClass + public static void setUpOutputDir() throws IOException { + outputDir = TestUtils.getResource("/org/sonar/plugins/jacoco/JaCoCoSensorTest/"); + jacocoExecutionData = new File(outputDir, "jacoco.exec"); + + Files.copy(TestUtils.getResource("Hello.class.toCopy"), new File(jacocoExecutionData.getParentFile(), "Hello.class")); + } + @Before public void setUp() { configuration = mock(JacocoConfiguration.class); @@ -60,6 +83,7 @@ public class JaCoCoSensorTest { public void shouldNotExecuteOnProject() { Project project = mock(Project.class); when(project.getLanguageKey()).thenReturn("flex"); + assertThat(sensor.shouldExecuteOnProject(project), is(false)); } @@ -67,23 +91,19 @@ public class JaCoCoSensorTest { public void shouldExecuteOnProject() { Project project = mock(Project.class); when(project.getLanguageKey()).thenReturn(Java.KEY); + assertThat(sensor.shouldExecuteOnProject(project), is(true)); } @Test - public void testReadExecutionData() throws Exception { - File jacocoExecutionData = new File(getClass().getResource("/org/sonar/plugins/jacoco/JaCoCoSensorTest/jacoco.exec").getFile()); - File buildOutputDir = jacocoExecutionData.getParentFile(); + public void testReadExecutionData() { + JavaFile resource = new JavaFile("org.sonar.plugins.jacoco.tests.Hello"); SensorContext context = mock(SensorContext.class); - - final JavaFile resource = new JavaFile("org.sonar.plugins.jacoco.tests.Hello"); - when(context.getResource(any(Resource.class))).thenReturn(resource); - ProjectFileSystem pfs = mock(ProjectFileSystem.class); - when(pfs.getBuildOutputDir()).thenReturn(buildOutputDir); - when(pfs.resolvePath(anyString())).thenReturn(jacocoExecutionData); - Project project = mock(Project.class); + when(context.getResource(any(Resource.class))).thenReturn(resource); + when(pfs.getBuildOutputDir()).thenReturn(outputDir); + when(pfs.resolvePath(anyString())).thenReturn(jacocoExecutionData); when(project.getFileSystem()).thenReturn(pfs); sensor.analyse(project, context); @@ -95,22 +115,19 @@ public class JaCoCoSensorTest { argThat(new IsMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA, "6=1;7=1;8=1;11=1;15=0;16=0;18=0"))); verify(context).saveMeasure(eq(resource), argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER, 2.0))); verify(context).saveMeasure(eq(resource), argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS, 2.0))); - verify(context).saveMeasure(eq(resource), argThat(new IsMeasure(CoreMetrics.CONDITIONS_BY_LINE, "15=2"))); + verify(context).saveMeasure(eq(resource), argThat(new IsMeasure(CoreMetrics.CONDITIONS_BY_LINE, "15=2" + + ""))); verify(context).saveMeasure(eq(resource), argThat(new IsMeasure(CoreMetrics.COVERED_CONDITIONS_BY_LINE, "15=0"))); verifyNoMoreInteractions(context); } @Test - public void doNotSaveMeasureOnResourceWhichDoesntExistInTheContext() throws Exception { - File jacocoExecutionData = new File(getClass().getResource("/org/sonar/plugins/jacoco/JaCoCoSensorTest/jacoco.exec").getFile()); - File buildOutputDir = jacocoExecutionData.getParentFile(); + public void doNotSaveMeasureOnResourceWhichDoesntExistInTheContext() { SensorContext context = mock(SensorContext.class); - when(context.getResource(any(Resource.class))).thenReturn(null); - ProjectFileSystem pfs = mock(ProjectFileSystem.class); - when(pfs.getBuildOutputDir()).thenReturn(buildOutputDir); - Project project = mock(Project.class); + when(context.getResource(any(Resource.class))).thenReturn(null); + when(pfs.getBuildOutputDir()).thenReturn(outputDir); when(project.getFileSystem()).thenReturn(pfs); sensor.analyse(project, context); diff --git a/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoSensorTest/Hello.class b/plugins/sonar-jacoco-plugin/src/test/resources/Hello.class.toCopy Binary files differindex e004f4f6149..e004f4f6149 100644 --- a/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoSensorTest/Hello.class +++ b/plugins/sonar-jacoco-plugin/src/test/resources/Hello.class.toCopy |