aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-02-19 12:34:19 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2015-02-19 12:34:45 +0100
commitf84e08449a133657226a78f26a3eee724e0210ea (patch)
tree63c693b8b917bc0cee1274a3a7fd6bf8b50093dc /plugins
parentd5a8ab383c56026165e995d62fbbeb0bed790d53 (diff)
downloadsonarqube-f84e08449a133657226a78f26a3eee724e0210ea.tar.gz
sonarqube-f84e08449a133657226a78f26a3eee724e0210ea.zip
SONAR-5772 Force coverage measure computation by default
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AbstractCoverageDecorator.java30
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/BranchCoverageDecorator.java6
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageDecorator.java10
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecorator.java5
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItCoverageDecorator.java6
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItLineCoverageDecorator.java6
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/LineCoverageDecorator.java8
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecorator.java6
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallCoverageDecorator.java6
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecorator.java6
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/BranchCoverageDecoratorTest.java3
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java37
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecoratorTest.java3
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java7
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItLineCoverageDecoratorTest.java7
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LineCoverageDecoratorTest.java30
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecoratorTest.java3
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java7
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecoratorTest.java9
19 files changed, 169 insertions, 26 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AbstractCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AbstractCoverageDecorator.java
index c4c39208422..eb900b148dc 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AbstractCoverageDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AbstractCoverageDecorator.java
@@ -19,10 +19,14 @@
*/
package org.sonar.plugins.core.sensors;
+import org.sonar.api.CoreProperties;
import org.sonar.api.batch.Decorator;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependedUpon;
+import org.sonar.api.config.Settings;
+import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
@@ -33,6 +37,30 @@ import java.util.Collection;
public abstract class AbstractCoverageDecorator implements Decorator {
+ private Settings settings;
+
+ public AbstractCoverageDecorator(Settings settings) {
+ this.settings = settings;
+ }
+
+ protected boolean isCoverageComputationForced() {
+ return !settings.getBoolean(CoreProperties.COVERAGE_UNFORCED_KEY);
+ }
+
+ protected long getLinesToCover(DecoratorContext context) {
+ Measure linesToCover = context.getMeasure(CoreMetrics.LINES_TO_COVER);
+ if (MeasureUtils.hasValue(linesToCover)) {
+ return linesToCover.getValue().longValue();
+ } else {
+ if (isCoverageComputationForced()) {
+ // SONAR-5772 as an approximation we consider that every ncloc is a line to cover
+ return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.NCLOC), 0L);
+ } else {
+ return 0L;
+ }
+ }
+ }
+
@Override
public boolean shouldExecuteOnProject(Project project) {
return true;
@@ -52,7 +80,7 @@ public abstract class AbstractCoverageDecorator implements Decorator {
}
protected boolean shouldDecorate(final Resource resource) {
- return !ResourceUtils.isUnitTestClass(resource);
+ return !ResourceUtils.isUnitTestFile(resource);
}
private void computeMeasure(DecoratorContext context) {
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/BranchCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/BranchCoverageDecorator.java
index 529883fc749..718a039f9c4 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/BranchCoverageDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/BranchCoverageDecorator.java
@@ -21,6 +21,7 @@ package org.sonar.plugins.core.sensors;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
+import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
@@ -29,6 +30,11 @@ import org.sonar.batch.sensor.coverage.CoverageConstants;
import java.util.Collection;
public final class BranchCoverageDecorator extends AbstractCoverageDecorator {
+
+ public BranchCoverageDecorator(Settings settings) {
+ super(settings);
+ }
+
@DependsUpon
public Collection<Metric> dependsUponMetrics() {
return CoverageConstants.BRANCH_COVERAGE_METRICS;
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageDecorator.java
index 46b02d4e0f8..950f584206b 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageDecorator.java
@@ -21,6 +21,7 @@ package org.sonar.plugins.core.sensors;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
+import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
@@ -29,6 +30,11 @@ import org.sonar.batch.sensor.coverage.CoverageConstants;
import java.util.Collection;
public final class CoverageDecorator extends AbstractCoverageDecorator {
+
+ public CoverageDecorator(Settings settings) {
+ super(settings);
+ }
+
@DependsUpon
public Collection<Metric> usedMetrics() {
return CoverageConstants.COVERAGE_METRICS;
@@ -41,10 +47,10 @@ public final class CoverageDecorator extends AbstractCoverageDecorator {
@Override
protected Long countElements(DecoratorContext context) {
- long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.LINES_TO_COVER), 0L);
+ long linesToCover = getLinesToCover(context);
long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER), 0L);
- return lines + conditions;
+ return linesToCover + conditions;
}
@Override
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecorator.java
index eb515e363a5..fcf30372efc 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecorator.java
@@ -22,6 +22,7 @@ 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.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
@@ -30,6 +31,10 @@ import java.util.List;
public final class ItBranchCoverageDecorator extends AbstractCoverageDecorator {
+ public ItBranchCoverageDecorator(Settings settings) {
+ super(settings);
+ }
+
@DependsUpon
public List<Metric> dependsUponMetrics() {
return ImmutableList.<Metric>of(CoreMetrics.IT_UNCOVERED_CONDITIONS, CoreMetrics.IT_CONDITIONS_TO_COVER,
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItCoverageDecorator.java
index a9bd603985a..a32ea0f32d2 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItCoverageDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItCoverageDecorator.java
@@ -22,6 +22,7 @@ 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.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
@@ -29,6 +30,11 @@ import org.sonar.api.measures.Metric;
import java.util.Collection;
public final class ItCoverageDecorator extends AbstractCoverageDecorator {
+
+ public ItCoverageDecorator(Settings settings) {
+ super(settings);
+ }
+
@DependsUpon
public Collection<Metric> usedMetrics() {
return ImmutableList.<Metric>of(CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.NEW_IT_LINES_TO_COVER,
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItLineCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItLineCoverageDecorator.java
index 651d379c92e..1c8fa95687c 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItLineCoverageDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItLineCoverageDecorator.java
@@ -22,6 +22,7 @@ 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.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
@@ -29,6 +30,11 @@ import org.sonar.api.measures.Metric;
import java.util.List;
public final class ItLineCoverageDecorator extends AbstractCoverageDecorator {
+
+ public ItLineCoverageDecorator(Settings settings) {
+ super(settings);
+ }
+
@DependsUpon
public List<Metric> dependsUponMetrics() {
return ImmutableList.<Metric>of(CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_LINES,
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/LineCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/LineCoverageDecorator.java
index 11ff93f0634..fa264751ef6 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/LineCoverageDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/LineCoverageDecorator.java
@@ -21,6 +21,7 @@ package org.sonar.plugins.core.sensors;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
+import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
@@ -29,6 +30,11 @@ import org.sonar.batch.sensor.coverage.CoverageConstants;
import java.util.Collection;
public final class LineCoverageDecorator extends AbstractCoverageDecorator {
+
+ public LineCoverageDecorator(Settings settings) {
+ super(settings);
+ }
+
@DependsUpon
public Collection<Metric> dependsUponMetrics() {
return CoverageConstants.LINE_COVERAGE_METRICS;
@@ -41,7 +47,7 @@ public final class LineCoverageDecorator extends AbstractCoverageDecorator {
@Override
protected Long countElements(DecoratorContext context) {
- return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.LINES_TO_COVER), 0L);
+ return getLinesToCover(context);
}
@Override
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecorator.java
index 2c54896f22d..54173d72965 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecorator.java
@@ -22,6 +22,7 @@ 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.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
@@ -29,6 +30,11 @@ import org.sonar.api.measures.Metric;
import java.util.List;
public final class OverallBranchCoverageDecorator extends AbstractCoverageDecorator {
+
+ public OverallBranchCoverageDecorator(Settings settings) {
+ super(settings);
+ }
+
@DependsUpon
public List<Metric> dependsUponMetrics() {
return ImmutableList.<Metric>of(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, CoreMetrics.OVERALL_CONDITIONS_TO_COVER,
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallCoverageDecorator.java
index 998e4b3ef24..0efb0113e87 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallCoverageDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallCoverageDecorator.java
@@ -22,6 +22,7 @@ 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.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
@@ -29,6 +30,11 @@ import org.sonar.api.measures.Metric;
import java.util.Collection;
public final class OverallCoverageDecorator extends AbstractCoverageDecorator {
+
+ public OverallCoverageDecorator(Settings settings) {
+ super(settings);
+ }
+
@DependsUpon
public Collection<Metric> usedMetrics() {
return ImmutableList.<Metric>of(CoreMetrics.OVERALL_LINES_TO_COVER, CoreMetrics.OVERALL_UNCOVERED_LINES, CoreMetrics.NEW_OVERALL_LINES_TO_COVER,
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecorator.java
index a3ab283cf9d..d66a8e79852 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecorator.java
@@ -22,6 +22,7 @@ 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.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
@@ -29,6 +30,11 @@ import org.sonar.api.measures.Metric;
import java.util.List;
public final class OverallLineCoverageDecorator extends AbstractCoverageDecorator {
+
+ public OverallLineCoverageDecorator(Settings settings) {
+ super(settings);
+ }
+
@DependsUpon
public List<Metric> dependsUponMetrics() {
return ImmutableList.<Metric>of(CoreMetrics.OVERALL_UNCOVERED_LINES, CoreMetrics.OVERALL_LINES_TO_COVER, CoreMetrics.NEW_OVERALL_UNCOVERED_LINES,
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/BranchCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/BranchCoverageDecoratorTest.java
index 6c88fb9aceb..be6d69ed9ed 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/BranchCoverageDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/BranchCoverageDecoratorTest.java
@@ -22,6 +22,7 @@ package org.sonar.plugins.core.sensors;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.resources.Project;
@@ -36,7 +37,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class BranchCoverageDecoratorTest {
- private final BranchCoverageDecorator decorator = new BranchCoverageDecorator();
+ private final BranchCoverageDecorator decorator = new BranchCoverageDecorator(new Settings());
private final Project resource = mock(Project.class);
@Before
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java
index 1db7fca5f62..d43e6c9aab1 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java
@@ -21,7 +21,9 @@ package org.sonar.plugins.core.sensors;
import org.junit.Before;
import org.junit.Test;
+import org.sonar.api.CoreProperties;
import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
@@ -31,20 +33,23 @@ import org.sonar.api.resources.Scopes;
import java.util.Collection;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.anyDouble;
-import static org.mockito.Mockito.eq;
+import static org.mockito.Matchers.anyDouble;
+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;
public class CoverageDecoratorTest {
- private final CoverageDecorator decorator = new CoverageDecorator();
+ private Settings settings;
+ private CoverageDecorator decorator;
private final Project project = mock(Project.class);
@Before
public void before() {
when(project.getScope()).thenReturn(Scopes.PROJECT);
+ settings = new Settings();
+ decorator = new CoverageDecorator(settings);
}
@Test
@@ -52,8 +57,8 @@ public class CoverageDecoratorTest {
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);
+ CoreMetrics.NEW_UNCOVERED_LINES, CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS,
+ CoreMetrics.NEW_CONDITIONS_TO_COVER, CoreMetrics.NEW_UNCOVERED_CONDITIONS);
}
@Test
@@ -67,6 +72,28 @@ public class CoverageDecoratorTest {
}
@Test
+ public void forceCoverageByDefault() {
+ DecoratorContext context = mock(DecoratorContext.class);
+ when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 100.0));
+
+ decorator.decorate(project, context);
+
+ verify(context).saveMeasure(CoreMetrics.COVERAGE, 0.0);
+ }
+
+ @Test
+ public void dontForceCoverage() {
+ settings.setProperty(CoreProperties.COVERAGE_UNFORCED_KEY, "true");
+
+ DecoratorContext context = mock(DecoratorContext.class);
+ when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 100.0));
+
+ decorator.decorate(project, context);
+
+ verify(context, never()).saveMeasure(eq(CoreMetrics.COVERAGE), anyDouble());
+ }
+
+ @Test
public void coverageCanBe0() {
DecoratorContext context = mockContext(50, 50, 5, 5);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecoratorTest.java
index 14ba49d0432..aeb02f57b56 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecoratorTest.java
@@ -22,6 +22,7 @@ package org.sonar.plugins.core.sensors;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.resources.Project;
@@ -36,7 +37,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class ItBranchCoverageDecoratorTest {
- private final ItBranchCoverageDecorator decorator = new ItBranchCoverageDecorator();
+ private final ItBranchCoverageDecorator decorator = new ItBranchCoverageDecorator(new Settings());
private final Project resource = mock(Project.class);
@Before
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java
index 78cbe32cfaa..77492714384 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java
@@ -22,6 +22,7 @@ package org.sonar.plugins.core.sensors;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
@@ -39,7 +40,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class ItCoverageDecoratorTest {
- private final ItCoverageDecorator decorator = new ItCoverageDecorator();
+ private final ItCoverageDecorator decorator = new ItCoverageDecorator(new Settings());
private final Project project = mock(Project.class);
@Before
@@ -52,8 +53,8 @@ public class ItCoverageDecoratorTest {
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);
+ 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
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItLineCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItLineCoverageDecoratorTest.java
index e88e72596ed..cf828aee1f2 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItLineCoverageDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItLineCoverageDecoratorTest.java
@@ -22,6 +22,7 @@ package org.sonar.plugins.core.sensors;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
@@ -31,15 +32,15 @@ import org.sonar.api.resources.Scopes;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.anyDouble;
-import static org.mockito.Mockito.eq;
+import static org.mockito.Matchers.anyDouble;
+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;
public class ItLineCoverageDecoratorTest {
- private final ItLineCoverageDecorator decorator = new ItLineCoverageDecorator();
+ private final ItLineCoverageDecorator decorator = new ItLineCoverageDecorator(new Settings());
private final Project project = mock(Project.class);
@Before
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LineCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LineCoverageDecoratorTest.java
index e2956df1683..0d5df65f8e4 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LineCoverageDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LineCoverageDecoratorTest.java
@@ -21,7 +21,9 @@ package org.sonar.plugins.core.sensors;
import org.junit.Before;
import org.junit.Test;
+import org.sonar.api.CoreProperties;
import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.resources.Project;
@@ -36,12 +38,16 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class LineCoverageDecoratorTest {
- private final LineCoverageDecorator decorator = new LineCoverageDecorator();
+
+ private Settings settings;
+ private LineCoverageDecorator decorator;
private final Project project = mock(Project.class);
@Before
public void before() {
when(project.getScope()).thenReturn(Scopes.PROJECT);
+ settings = new Settings();
+ decorator = new LineCoverageDecorator(settings);
}
@Test
@@ -70,6 +76,28 @@ public class LineCoverageDecoratorTest {
}
@Test
+ public void forceCoverageByDefault() {
+ DecoratorContext context = mock(DecoratorContext.class);
+ when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 100.0));
+
+ decorator.decorate(project, context);
+
+ verify(context).saveMeasure(CoreMetrics.LINE_COVERAGE, 0.0);
+ }
+
+ @Test
+ public void dontForceCoverage() {
+ settings.setProperty(CoreProperties.COVERAGE_UNFORCED_KEY, "true");
+
+ DecoratorContext context = mock(DecoratorContext.class);
+ when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 100.0));
+
+ decorator.decorate(project, context);
+
+ verify(context, never()).saveMeasure(eq(CoreMetrics.LINE_COVERAGE), anyDouble());
+ }
+
+ @Test
public void allCoveredLines() {
DecoratorContext context = mockContext(50, 00);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecoratorTest.java
index 9f18f71df70..6b18547f8e6 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecoratorTest.java
@@ -22,6 +22,7 @@ package org.sonar.plugins.core.sensors;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.resources.Project;
@@ -36,7 +37,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class OverallBranchCoverageDecoratorTest {
- private final OverallBranchCoverageDecorator decorator = new OverallBranchCoverageDecorator();
+ private final OverallBranchCoverageDecorator decorator = new OverallBranchCoverageDecorator(new Settings());
private final Project resource = mock(Project.class);
@Before
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java
index c7c36505448..45bd2d25d4f 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java
@@ -22,6 +22,7 @@ package org.sonar.plugins.core.sensors;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
@@ -39,7 +40,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class OverallCoverageDecoratorTest {
- private final OverallCoverageDecorator decorator = new OverallCoverageDecorator();
+ private final OverallCoverageDecorator decorator = new OverallCoverageDecorator(new Settings());
private final Project project = mock(Project.class);
@Before
@@ -52,8 +53,8 @@ public class OverallCoverageDecoratorTest {
Collection<Metric> metrics = decorator.usedMetrics();
assertThat(metrics).containsOnly(CoreMetrics.OVERALL_LINES_TO_COVER, CoreMetrics.OVERALL_UNCOVERED_LINES, CoreMetrics.NEW_OVERALL_LINES_TO_COVER,
- CoreMetrics.NEW_OVERALL_UNCOVERED_LINES, CoreMetrics.OVERALL_CONDITIONS_TO_COVER, CoreMetrics.OVERALL_UNCOVERED_CONDITIONS,
- CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER, CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS);
+ CoreMetrics.NEW_OVERALL_UNCOVERED_LINES, CoreMetrics.OVERALL_CONDITIONS_TO_COVER, CoreMetrics.OVERALL_UNCOVERED_CONDITIONS,
+ CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER, CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS);
}
@Test
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecoratorTest.java
index 988094c2315..96a38f5f921 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecoratorTest.java
@@ -22,6 +22,7 @@ package org.sonar.plugins.core.sensors;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
@@ -31,15 +32,15 @@ import org.sonar.api.resources.Scopes;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.anyDouble;
-import static org.mockito.Mockito.eq;
+import static org.mockito.Matchers.anyDouble;
+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;
public class OverallLineCoverageDecoratorTest {
- private final OverallLineCoverageDecorator decorator = new OverallLineCoverageDecorator();
+ private final OverallLineCoverageDecorator decorator = new OverallLineCoverageDecorator(new Settings());
private final Project project = mock(Project.class);
@Before
@@ -52,7 +53,7 @@ public class OverallLineCoverageDecoratorTest {
List<Metric> metrics = decorator.dependsUponMetrics();
assertThat(metrics).containsOnly(CoreMetrics.OVERALL_UNCOVERED_LINES, CoreMetrics.OVERALL_LINES_TO_COVER, CoreMetrics.NEW_OVERALL_UNCOVERED_LINES,
- CoreMetrics.NEW_OVERALL_LINES_TO_COVER);
+ CoreMetrics.NEW_OVERALL_LINES_TO_COVER);
}
@Test