aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-core-plugin/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-02-19 14:46:17 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2015-02-19 15:09:29 +0100
commit91154a424d84bcc708cd95d18e86f582f218cd18 (patch)
tree069f5b1d46e1bcf46982446807b0e8cf14723594 /plugins/sonar-core-plugin/src
parent97b75e446c28d8c90b7c42575b54ceb233ac7920 (diff)
downloadsonarqube-91154a424d84bcc708cd95d18e86f582f218cd18.tar.gz
sonarqube-91154a424d84bcc708cd95d18e86f582f218cd18.zip
SONAR-5772 Force coverage measure computation by default
Diffstat (limited to 'plugins/sonar-core-plugin/src')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java2
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AbstractCoverageDecorator.java28
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/BranchCoverageDecorator.java5
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageDecorator.java7
-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.java5
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItLineCoverageDecorator.java5
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/LineCoverageDecorator.java7
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/LinesToCoverDecorator.java68
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecorator.java5
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallCoverageDecorator.java5
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecorator.java5
-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.java28
-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.java3
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItLineCoverageDecoratorTest.java3
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LineCoverageDecoratorTest.java28
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LinesToCoverDecoratorTest.java105
-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.java3
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecoratorTest.java3
22 files changed, 186 insertions, 143 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
index 49e1132f0e6..de837958f32 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
@@ -47,6 +47,7 @@ import org.sonar.plugins.core.sensors.ItBranchCoverageDecorator;
import org.sonar.plugins.core.sensors.ItCoverageDecorator;
import org.sonar.plugins.core.sensors.ItLineCoverageDecorator;
import org.sonar.plugins.core.sensors.LineCoverageDecorator;
+import org.sonar.plugins.core.sensors.LinesToCoverDecorator;
import org.sonar.plugins.core.sensors.ManualMeasureDecorator;
import org.sonar.plugins.core.sensors.OverallBranchCoverageDecorator;
import org.sonar.plugins.core.sensors.OverallCoverageDecorator;
@@ -335,6 +336,7 @@ public final class CorePlugin extends SonarPlugin {
DirectoriesDecorator.class,
FilesDecorator.class,
ManualMeasureDecorator.class,
+ LinesToCoverDecorator.class,
// time machine
TendencyDecorator.class,
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 eb900b148dc..8b287506247 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,14 +19,10 @@
*/
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;
@@ -37,30 +33,6 @@ 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;
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 718a039f9c4..c154440ea39 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,7 +21,6 @@ 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;
@@ -31,10 +30,6 @@ 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 950f584206b..0eb539f24b0 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,7 +21,6 @@ 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;
@@ -31,10 +30,6 @@ 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;
@@ -47,7 +42,7 @@ public final class CoverageDecorator extends AbstractCoverageDecorator {
@Override
protected Long countElements(DecoratorContext context) {
- long linesToCover = getLinesToCover(context);
+ long linesToCover = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.LINES_TO_COVER), 0L);
long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER), 0L);
return linesToCover + conditions;
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 fcf30372efc..eb515e363a5 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,7 +22,6 @@ 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;
@@ -31,10 +30,6 @@ 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 a32ea0f32d2..9b2d990b48c 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,7 +22,6 @@ 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;
@@ -31,10 +30,6 @@ 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 1c8fa95687c..f829393180e 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,7 +22,6 @@ 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;
@@ -31,10 +30,6 @@ 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 fa264751ef6..ebc29af0023 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,7 +21,6 @@ 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;
@@ -31,10 +30,6 @@ 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;
@@ -47,7 +42,7 @@ public final class LineCoverageDecorator extends AbstractCoverageDecorator {
@Override
protected Long countElements(DecoratorContext context) {
- return getLinesToCover(context);
+ return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.LINES_TO_COVER), 0L);
}
@Override
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/LinesToCoverDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/LinesToCoverDecorator.java
new file mode 100644
index 00000000000..65970a6582d
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/LinesToCoverDecorator.java
@@ -0,0 +1,68 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+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.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;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Resource;
+
+public final class LinesToCoverDecorator implements Decorator {
+
+ private final Settings settings;
+
+ public LinesToCoverDecorator(Settings settings) {
+ this.settings = settings;
+ }
+
+ @DependsUpon
+ public Metric dependsUpon() {
+ return CoreMetrics.NCLOC;
+ }
+
+ @DependedUpon
+ public Metric provides() {
+ return CoreMetrics.LINES_TO_COVER;
+ }
+
+ @Override
+ public boolean shouldExecuteOnProject(Project project) {
+ return !settings.getBoolean(CoreProperties.COVERAGE_UNFORCED_KEY);
+ }
+
+ @Override
+ public void decorate(Resource resource, DecoratorContext context) {
+ if (Qualifiers.isFile(resource)) {
+ if (!MeasureUtils.hasValue(context.getMeasure(CoreMetrics.LINES_TO_COVER))) {
+ double ncloc = MeasureUtils.getValue(context.getMeasure(CoreMetrics.NCLOC), 0.0);
+ context.saveMeasure(CoreMetrics.LINES_TO_COVER, ncloc);
+ context.saveMeasure(CoreMetrics.UNCOVERED_LINES, ncloc);
+ }
+ }
+ }
+}
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 54173d72965..2407269613a 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,7 +22,6 @@ 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;
@@ -31,10 +30,6 @@ 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 0efb0113e87..49602e6c04a 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,7 +22,6 @@ 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;
@@ -31,10 +30,6 @@ 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 d66a8e79852..c6f53a2aaac 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,7 +22,6 @@ 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;
@@ -31,10 +30,6 @@ 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 be6d69ed9ed..6c88fb9aceb 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,7 +22,6 @@ 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;
@@ -37,7 +36,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class BranchCoverageDecoratorTest {
- private final BranchCoverageDecorator decorator = new BranchCoverageDecorator(new Settings());
+ private final BranchCoverageDecorator decorator = new BranchCoverageDecorator();
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 d43e6c9aab1..0404cded7a1 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,9 +21,7 @@ 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;
@@ -41,15 +39,13 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class CoverageDecoratorTest {
- 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);
+ decorator = new CoverageDecorator();
}
@Test
@@ -72,28 +68,6 @@ 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 aeb02f57b56..14ba49d0432 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,7 +22,6 @@ 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;
@@ -37,7 +36,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class ItBranchCoverageDecoratorTest {
- private final ItBranchCoverageDecorator decorator = new ItBranchCoverageDecorator(new Settings());
+ private final ItBranchCoverageDecorator decorator = new ItBranchCoverageDecorator();
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 77492714384..08a82034a43 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,7 +22,6 @@ 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;
@@ -40,7 +39,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class ItCoverageDecoratorTest {
- private final ItCoverageDecorator decorator = new ItCoverageDecorator(new Settings());
+ private final ItCoverageDecorator decorator = new ItCoverageDecorator();
private final Project project = mock(Project.class);
@Before
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 cf828aee1f2..976b0442ac6 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,7 +22,6 @@ 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;
@@ -40,7 +39,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class ItLineCoverageDecoratorTest {
- private final ItLineCoverageDecorator decorator = new ItLineCoverageDecorator(new Settings());
+ private final ItLineCoverageDecorator decorator = new ItLineCoverageDecorator();
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 0d5df65f8e4..3381182889f 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,9 +21,7 @@ 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;
@@ -39,15 +37,13 @@ import static org.mockito.Mockito.when;
public class LineCoverageDecoratorTest {
- 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);
+ decorator = new LineCoverageDecorator();
}
@Test
@@ -76,28 +72,6 @@ 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/LinesToCoverDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LinesToCoverDecoratorTest.java
new file mode 100644
index 00000000000..1b9d9c25f6d
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LinesToCoverDecoratorTest.java
@@ -0,0 +1,105 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+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.PropertyDefinitions;
+import org.sonar.api.config.Settings;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.measures.Measure;
+import org.sonar.api.resources.Directory;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.Project;
+import org.sonar.core.config.CorePropertyDefinitions;
+
+import static org.assertj.core.api.Assertions.assertThat;
+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.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+public class LinesToCoverDecoratorTest {
+
+ private Settings settings;
+ private LinesToCoverDecorator decorator;
+
+ @Before
+ public void prepare() {
+ settings = new Settings(new PropertyDefinitions(CorePropertyDefinitions.all()));
+ decorator = new LinesToCoverDecorator(settings);
+ }
+
+ @Test
+ public void increaseCoverage() {
+ assertThat(decorator.provides()).isEqualTo(CoreMetrics.LINES_TO_COVER);
+ assertThat(decorator.dependsUpon()).isEqualTo(CoreMetrics.NCLOC);
+ }
+
+ @Test
+ public void testShouldExecute() {
+ assertThat(decorator.shouldExecuteOnProject(new Project("foo"))).isTrue();
+ settings.setProperty(CoreProperties.COVERAGE_UNFORCED_KEY, "true");
+ assertThat(decorator.shouldExecuteOnProject(new Project("foo"))).isFalse();
+ }
+
+ @Test
+ public void testExecuteOnlyOnMainFile() {
+ DecoratorContext context = mock(DecoratorContext.class);
+ decorator.decorate(File.create("test/FooTest.java", Java.INSTANCE, true), context);
+ decorator.decorate(Directory.create("src"), context);
+ decorator.decorate(new Project("foo"), context);
+ verifyNoMoreInteractions(context);
+ }
+
+ @Test
+ public void dontDoAnythingIfLinesToCoverAlreadyDefined() {
+ DecoratorContext context = mock(DecoratorContext.class);
+ File file = File.create("src/Foo.java");
+
+ when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(new Measure<>(CoreMetrics.LINES_TO_COVER, 0.0));
+ when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure<>(CoreMetrics.NCLOC, 10.0));
+
+ decorator.decorate(file, context);
+
+ verify(context, never()).saveMeasure(eq(CoreMetrics.LINES_TO_COVER), anyDouble());
+ verify(context, never()).saveMeasure(eq(CoreMetrics.UNCOVERED_LINES), anyDouble());
+ }
+
+ @Test
+ public void testUseNclocAsLinesToCover() {
+ DecoratorContext context = mock(DecoratorContext.class);
+ File file = File.create("src/Foo.java");
+
+ when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(null);
+ when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure<>(CoreMetrics.NCLOC, 10.0));
+
+ decorator.decorate(file, context);
+
+ verify(context).saveMeasure(CoreMetrics.LINES_TO_COVER, 10.0);
+ verify(context).saveMeasure(CoreMetrics.UNCOVERED_LINES, 10.0);
+ }
+}
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 6b18547f8e6..9f18f71df70 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,7 +22,6 @@ 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;
@@ -37,7 +36,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class OverallBranchCoverageDecoratorTest {
- private final OverallBranchCoverageDecorator decorator = new OverallBranchCoverageDecorator(new Settings());
+ private final OverallBranchCoverageDecorator decorator = new OverallBranchCoverageDecorator();
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 45bd2d25d4f..9aa79b1bbfb 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,7 +22,6 @@ 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;
@@ -40,7 +39,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class OverallCoverageDecoratorTest {
- private final OverallCoverageDecorator decorator = new OverallCoverageDecorator(new Settings());
+ private final OverallCoverageDecorator decorator = new OverallCoverageDecorator();
private final Project project = mock(Project.class);
@Before
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 96a38f5f921..c19e51755dd 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,7 +22,6 @@ 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;
@@ -40,7 +39,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class OverallLineCoverageDecoratorTest {
- private final OverallLineCoverageDecorator decorator = new OverallLineCoverageDecorator(new Settings());
+ private final OverallLineCoverageDecorator decorator = new OverallLineCoverageDecorator();
private final Project project = mock(Project.class);
@Before