*/
package org.sonar.plugins.core.sensors;
+import com.google.common.collect.ImmutableList;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
-import java.util.Arrays;
import java.util.List;
public final class AllTestsBranchCoverageDecorator extends AbstractCoverageDecorator {
-
@DependsUpon
public List<Metric> dependsUponMetrics() {
- return Arrays.asList(CoreMetrics.MERGED_UNCOVERED_CONDITIONS, CoreMetrics.MERGED_CONDITIONS_TO_COVER,
+ return ImmutableList.of(CoreMetrics.MERGED_UNCOVERED_CONDITIONS, CoreMetrics.MERGED_CONDITIONS_TO_COVER,
CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS, CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER);
}
protected long countCoveredElements(DecoratorContext context) {
long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS), 0L);
long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER), 0L);
+
return conditions - uncoveredConditions;
}
protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
long uncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS), periodIndex, 0L);
long conditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L);
+
return conditions - uncoveredConditions;
}
}
*/
package org.sonar.plugins.core.sensors;
+import com.google.common.collect.ImmutableList;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
-import java.util.Arrays;
import java.util.Collection;
public final class AllTestsCoverageDecorator extends AbstractCoverageDecorator {
-
@DependsUpon
public Collection<Metric> usedMetrics() {
- return Arrays.asList(CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.NEW_MERGED_LINES_TO_COVER,
+ return ImmutableList.of(CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.NEW_MERGED_LINES_TO_COVER,
CoreMetrics.NEW_MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_CONDITIONS_TO_COVER, CoreMetrics.MERGED_UNCOVERED_CONDITIONS,
CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS);
}
protected Long countElements(DecoratorContext context) {
long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L);
long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER), 0L);
+
return lines + conditions;
}
long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L);
long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS), 0L);
long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER), 0L);
+
return lines + conditions - uncoveredConditions - uncoveredLines;
}
-
@Override
protected Metric getGeneratedMetricForNewCode() {
return CoreMetrics.NEW_MERGED_COVERAGE;
@Override
protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
Long newLinesToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_LINES_TO_COVER), periodIndex);
- if (newLinesToCover != null) {
- long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L);
- return newLinesToCover + newConditionsToCover;
+ if (newLinesToCover == null) {
+ return null;
}
- return null;
+
+ long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L);
+
+ return newLinesToCover + newConditionsToCover;
}
@Override
long newUncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_LINES), periodIndex, 0L);
long newUncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS), periodIndex, 0L);
long newConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L);
+
return newLines + newConditions - newUncoveredConditions - newUncoveredLines;
}
-}
\ No newline at end of file
+}
*/
package org.sonar.plugins.core.sensors;
+import com.google.common.collect.ImmutableList;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
-import java.util.Arrays;
import java.util.List;
public final class AllTestsLineCoverageDecorator extends AbstractCoverageDecorator {
@DependsUpon
public List<Metric> dependsUponMetrics() {
- return Arrays.asList(CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_LINES,
+ return ImmutableList.of(CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_LINES,
CoreMetrics.NEW_MERGED_LINES_TO_COVER);
}
protected long countCoveredElements(DecoratorContext context) {
long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_LINES), 0L);
long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L);
+
return lines - uncoveredLines;
}
-
@Override
protected Metric getGeneratedMetricForNewCode() {
return CoreMetrics.NEW_MERGED_LINE_COVERAGE;
protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
long uncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_LINES), periodIndex, 0L);
long lines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_LINES_TO_COVER), periodIndex, 0L);
+
return lines - uncoveredLines;
}
}
*/
package org.sonar.plugins.core.sensors;
+import com.google.common.collect.ImmutableList;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
-import java.util.Arrays;
import java.util.List;
public final class BranchCoverageDecorator extends AbstractCoverageDecorator {
-
@DependsUpon
public List<Metric> dependsUponMetrics() {
- return Arrays.asList(CoreMetrics.UNCOVERED_CONDITIONS, CoreMetrics.CONDITIONS_TO_COVER,
+ return ImmutableList.of(CoreMetrics.UNCOVERED_CONDITIONS, CoreMetrics.CONDITIONS_TO_COVER,
CoreMetrics.NEW_UNCOVERED_CONDITIONS, CoreMetrics.NEW_CONDITIONS_TO_COVER);
}
protected long countCoveredElements(DecoratorContext context) {
long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS), 0L);
long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER), 0L);
+
return conditions - uncoveredConditions;
}
protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
long uncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_UNCOVERED_CONDITIONS), periodIndex, 0L);
long conditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER), periodIndex, 0L);
+
return conditions - uncoveredConditions;
}
}
*/
package org.sonar.plugins.core.sensors;
+import com.google.common.collect.ImmutableList;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
-import java.util.Arrays;
import java.util.Collection;
public final class CoverageDecorator extends AbstractCoverageDecorator {
-
@DependsUpon
public Collection<Metric> usedMetrics() {
- return Arrays.asList(CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.NEW_LINES_TO_COVER,
- CoreMetrics.NEW_UNCOVERED_LINES, CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS,
- CoreMetrics.NEW_CONDITIONS_TO_COVER, CoreMetrics.NEW_UNCOVERED_CONDITIONS);
+ return ImmutableList.of(CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.NEW_LINES_TO_COVER,
+ CoreMetrics.NEW_UNCOVERED_LINES, CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS,
+ CoreMetrics.NEW_CONDITIONS_TO_COVER, CoreMetrics.NEW_UNCOVERED_CONDITIONS);
}
@Override
protected Long countElements(DecoratorContext context) {
long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.LINES_TO_COVER), 0L);
long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER), 0L);
+
return lines + conditions;
}
long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.LINES_TO_COVER), 0L);
long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS), 0L);
long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER), 0L);
+
return lines + conditions - uncoveredConditions - uncoveredLines;
}
-
@Override
protected Metric getGeneratedMetricForNewCode() {
return CoreMetrics.NEW_COVERAGE;
@Override
protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
Long newLinesToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_LINES_TO_COVER), periodIndex);
- if (newLinesToCover != null) {
- long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER), periodIndex, 0L);
- return newLinesToCover + newConditionsToCover;
+ if (newLinesToCover == null) {
+ return null;
}
- return null;
+
+ long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER), periodIndex, 0L);
+
+ return newLinesToCover + newConditionsToCover;
}
@Override
long newUncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_UNCOVERED_LINES), periodIndex, 0L);
long newUncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_UNCOVERED_CONDITIONS), periodIndex, 0L);
long newConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER), periodIndex, 0L);
+
return newLines + newConditions - newUncoveredConditions - newUncoveredLines;
}
-}
\ No newline at end of file
+}
*/
package org.sonar.plugins.core.sensors;
+import com.google.common.collect.ImmutableList;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
-import java.util.Arrays;
import java.util.List;
public final class ItBranchCoverageDecorator extends AbstractCoverageDecorator {
@DependsUpon
public List<Metric> dependsUponMetrics() {
- return Arrays.asList(CoreMetrics.IT_UNCOVERED_CONDITIONS, CoreMetrics.IT_CONDITIONS_TO_COVER,
+ return ImmutableList.of(CoreMetrics.IT_UNCOVERED_CONDITIONS, CoreMetrics.IT_CONDITIONS_TO_COVER,
CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS, CoreMetrics.NEW_IT_CONDITIONS_TO_COVER);
}
protected long countCoveredElements(DecoratorContext context) {
long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_UNCOVERED_CONDITIONS), 0L);
long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER), 0L);
+
return conditions - uncoveredConditions;
}
protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
long uncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS), periodIndex, 0L);
long conditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER), periodIndex, 0L);
+
return conditions - uncoveredConditions;
}
}
*/
package org.sonar.plugins.core.sensors;
+import com.google.common.collect.ImmutableList;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
-import java.util.Arrays;
import java.util.Collection;
public final class ItCoverageDecorator extends AbstractCoverageDecorator {
-
@DependsUpon
public Collection<Metric> usedMetrics() {
- return Arrays.asList(CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.NEW_IT_LINES_TO_COVER,
+ return ImmutableList.of(CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.NEW_IT_LINES_TO_COVER,
CoreMetrics.NEW_IT_UNCOVERED_LINES, CoreMetrics.IT_CONDITIONS_TO_COVER, CoreMetrics.IT_UNCOVERED_CONDITIONS,
CoreMetrics.NEW_IT_CONDITIONS_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS);
}
protected Long countElements(DecoratorContext context) {
long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER), 0L);
long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER), 0L);
+
return lines + conditions;
}
long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER), 0L);
long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_UNCOVERED_CONDITIONS), 0L);
long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER), 0L);
+
return lines + conditions - uncoveredConditions - uncoveredLines;
}
-
@Override
protected Metric getGeneratedMetricForNewCode() {
return CoreMetrics.NEW_IT_COVERAGE;
@Override
protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
Long newLinesToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_LINES_TO_COVER), periodIndex);
- if (newLinesToCover != null) {
- long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER), periodIndex, 0L);
- return newLinesToCover + newConditionsToCover;
+ if (newLinesToCover == null) {
+ return null;
}
- return null;
+
+ long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER), periodIndex, 0L);
+ return newLinesToCover + newConditionsToCover;
}
@Override
long newUncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_UNCOVERED_LINES), periodIndex, 0L);
long newUncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS), periodIndex, 0L);
long newConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER), periodIndex, 0L);
+
return newLines + newConditions - newUncoveredConditions - newUncoveredLines;
}
-}
\ No newline at end of file
+}
*/
package org.sonar.plugins.core.sensors;
+import com.google.common.collect.ImmutableList;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
-import java.util.Arrays;
import java.util.List;
public final class ItLineCoverageDecorator extends AbstractCoverageDecorator {
-
@DependsUpon
public List<Metric> dependsUponMetrics() {
- return Arrays.asList(CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_LINES,
+ return ImmutableList.of(CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_LINES,
CoreMetrics.NEW_IT_LINES_TO_COVER);
}
protected long countCoveredElements(DecoratorContext context) {
long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_UNCOVERED_LINES), 0L);
long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER), 0L);
+
return lines - uncoveredLines;
}
-
@Override
protected Metric getGeneratedMetricForNewCode() {
return CoreMetrics.NEW_IT_LINE_COVERAGE;
protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
long uncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_UNCOVERED_LINES), periodIndex, 0L);
long lines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_LINES_TO_COVER), periodIndex, 0L);
+
return lines - uncoveredLines;
}
}
*/
package org.sonar.plugins.core.sensors;
+import com.google.common.collect.ImmutableList;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
-import java.util.Arrays;
import java.util.List;
public final class LineCoverageDecorator extends AbstractCoverageDecorator {
-
@DependsUpon
public List<Metric> dependsUponMetrics() {
- return Arrays.asList(CoreMetrics.UNCOVERED_LINES, CoreMetrics.LINES_TO_COVER, CoreMetrics.NEW_UNCOVERED_LINES,
+ return ImmutableList.of(CoreMetrics.UNCOVERED_LINES, CoreMetrics.LINES_TO_COVER, CoreMetrics.NEW_UNCOVERED_LINES,
CoreMetrics.NEW_LINES_TO_COVER);
}
protected long countCoveredElements(DecoratorContext context) {
long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.UNCOVERED_LINES), 0L);
long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.LINES_TO_COVER), 0L);
+
return lines - uncoveredLines;
}
-
@Override
protected Metric getGeneratedMetricForNewCode() {
return CoreMetrics.NEW_LINE_COVERAGE;
protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
long uncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_UNCOVERED_LINES), periodIndex, 0L);
long lines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_LINES_TO_COVER), periodIndex, 0L);
+
return lines - uncoveredLines;
}
}
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Scopes;
+import java.util.Collection;
+
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.eq;
when(project.getScope()).thenReturn(Scopes.PROJECT);
}
+ @Test
+ public void should_use_metrics() {
+ Collection<Metric> metrics = decorator.usedMetrics();
+
+ assertThat(metrics).containsOnly(CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.NEW_MERGED_LINES_TO_COVER,
+ CoreMetrics.NEW_MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_CONDITIONS_TO_COVER, CoreMetrics.MERGED_UNCOVERED_CONDITIONS,
+ CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS);
+ }
+
@Test
public void noCoverageWhenStaticAnalysis() {
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Scopes;
+import java.util.Collection;
+
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.anyDouble;
import static org.mockito.Mockito.eq;
when(project.getScope()).thenReturn(Scopes.PROJECT);
}
+ @Test
+ public void should_use_metrics() {
+ Collection<Metric> metrics = decorator.usedMetrics();
+
+ assertThat(metrics).containsOnly(CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.NEW_LINES_TO_COVER,
+ CoreMetrics.NEW_UNCOVERED_LINES, CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS,
+ CoreMetrics.NEW_CONDITIONS_TO_COVER, CoreMetrics.NEW_UNCOVERED_CONDITIONS);
+ }
+
@Test
public void noCoverageWhenStaticAnalysis() {
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Scopes;
+import java.util.Collection;
+
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.eq;
when(project.getScope()).thenReturn(Scopes.PROJECT);
}
+ @Test
+ public void should_use_metrics() {
+ Collection<Metric> metrics = decorator.usedMetrics();
+
+ assertThat(metrics).containsOnly(CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.NEW_IT_LINES_TO_COVER,
+ CoreMetrics.NEW_IT_UNCOVERED_LINES, CoreMetrics.IT_CONDITIONS_TO_COVER, CoreMetrics.IT_UNCOVERED_CONDITIONS,
+ CoreMetrics.NEW_IT_CONDITIONS_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS);
+ }
+
@Test
public void noCoverageWhenStaticAnalysis() {
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
import org.sonar.api.measures.Measure;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.Project;
-import org.sonar.api.resources.ProjectFileSystem;
import org.sonar.api.utils.SonarException;
import java.io.BufferedInputStream;
private static final String MERGED_EXEC = "target/merged.exec";
private final JacocoConfiguration configuration;
- private final ProjectFileSystem projectFileSystem;
- public JaCoCoAllTestsSensor(JacocoConfiguration configuration, ProjectFileSystem projectFileSystem) {
+ public JaCoCoAllTestsSensor(JacocoConfiguration configuration) {
this.configuration = configuration;
- this.projectFileSystem = projectFileSystem;
}
public boolean shouldExecuteOnProject(Project project) {
}
public void analyse(Project project, SensorContext context) {
- mergeReports();
+ mergeReports(project);
+
new AllTestsAnalyzer().analyse(project, context);
}
- private void mergeReports() {
- String reportUTs = configuration.getReportPath();
- String reportITs = configuration.getItReportPath();
- String reportAllTests = MERGED_EXEC;
+ private void mergeReports(Project project) {
+ File baseDir = project.getFileSystem().getBasedir();
- File baseDir = projectFileSystem.getBasedir();
- File destFile = new File(baseDir, reportAllTests);
+ File reportUTs = new File(baseDir, configuration.getReportPath());
+ File reportITs = new File(baseDir, configuration.getItReportPath());
+ File reportAllTests = new File(baseDir, MERGED_EXEC);
- final SessionInfoStore infoStore = new SessionInfoStore();
- final ExecutionDataStore dataStore = new ExecutionDataStore();
+ SessionInfoStore infoStore = new SessionInfoStore();
+ ExecutionDataStore dataStore = new ExecutionDataStore();
- loadSourceFiles(infoStore, dataStore, new File(baseDir, reportUTs), new File(baseDir, reportITs));
+ loadSourceFiles(infoStore, dataStore, reportUTs, reportITs);
BufferedOutputStream outputStream = null;
try {
- outputStream = new BufferedOutputStream(new FileOutputStream(destFile));
+ outputStream = new BufferedOutputStream(new FileOutputStream(reportAllTests));
ExecutionDataWriter dataWriter = new ExecutionDataWriter(outputStream);
infoStore.accept(dataWriter);
dataStore.accept(dataWriter);
} catch (IOException e) {
- throw new SonarException(String.format("Unable to write merged file %s", destFile.getAbsolutePath()), e);
+ throw new SonarException(String.format("Unable to write merged file %s", reportAllTests.getAbsolutePath()), e);
} finally {
Closeables.closeQuietly(outputStream);
}
@Override
protected void saveMeasures(SensorContext context, JavaFile resource, Collection<Measure> measures) {
for (Measure measure : measures) {
- Measure mergedMeasure = convertForIT(measure);
+ Measure mergedMeasure = convertForAllTests(measure);
if (mergedMeasure != null) {
context.saveMeasure(resource, mergedMeasure);
}
}
}
- private Measure convertForIT(Measure measure) {
+ private Measure convertForAllTests(Measure measure) {
if (CoreMetrics.LINES_TO_COVER.equals(measure.getMetric())) {
return new Measure(CoreMetrics.MERGED_LINES_TO_COVER, measure.getValue());
} else if (CoreMetrics.UNCOVERED_LINES.equals(measure.getMetric())) {