import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.List;
-import org.sonar.batch.compute.BranchCoverageDecorator;
import org.sonar.batch.compute.CommentDensityDecorator;
-import org.sonar.batch.compute.CoverageDecorator;
import org.sonar.batch.compute.DirectoriesDecorator;
import org.sonar.batch.compute.FilesDecorator;
-import org.sonar.batch.compute.ItBranchCoverageDecorator;
-import org.sonar.batch.compute.ItCoverageDecorator;
-import org.sonar.batch.compute.ItLineCoverageDecorator;
-import org.sonar.batch.compute.LineCoverageDecorator;
-import org.sonar.batch.compute.OverallBranchCoverageDecorator;
-import org.sonar.batch.compute.OverallCoverageDecorator;
-import org.sonar.batch.compute.OverallLineCoverageDecorator;
import org.sonar.batch.compute.UnitTestDecorator;
import org.sonar.batch.cpd.CpdComponents;
import org.sonar.batch.issue.tracking.IssueTracking;
import org.sonar.batch.scm.ScmSensor;
import org.sonar.batch.source.CodeColorizerSensor;
import org.sonar.batch.source.LinesSensor;
-import org.sonar.core.config.CorePropertyDefinitions;
import org.sonar.core.component.DefaultResourceTypes;
+import org.sonar.core.config.CorePropertyDefinitions;
public class BatchComponents {
private BatchComponents() {
// to be moved to compute engine
UnitTestDecorator.class,
- LineCoverageDecorator.class,
- CoverageDecorator.class,
- BranchCoverageDecorator.class,
- ItLineCoverageDecorator.class,
- ItCoverageDecorator.class,
- ItBranchCoverageDecorator.class,
- OverallLineCoverageDecorator.class,
- OverallCoverageDecorator.class,
- OverallBranchCoverageDecorator.class,
CommentDensityDecorator.class,
DirectoriesDecorator.class,
FilesDecorator.class
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.DependedUpon;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-
-public abstract class AbstractCoverageDecorator implements Decorator {
-
- @Override
- public boolean shouldExecuteOnProject(Project project) {
- return true;
- }
-
- @DependedUpon
- public Collection<Metric> generatedMetrics() {
- return Arrays.asList(getGeneratedMetric(), getGeneratedMetricForNewCode());
- }
-
- @Override
- public void decorate(final Resource resource, final DecoratorContext context) {
- if (shouldDecorate(resource)) {
- computeMeasure(context);
- computeMeasureForNewCode(context);
- }
- }
-
- protected boolean shouldDecorate(final Resource resource) {
- return !ResourceUtils.isUnitTestFile(resource);
- }
-
- private void computeMeasure(DecoratorContext context) {
- if (context.getMeasure(getGeneratedMetric()) == null) {
- Long elements = countElements(context);
- if (elements != null && elements > 0L) {
- Long coveredElements = countCoveredElements(context);
- context.saveMeasure(getGeneratedMetric(), calculateCoverage(coveredElements, elements));
- }
- }
- }
-
- private void computeMeasureForNewCode(DecoratorContext context) {
- if (context.getMeasure(getGeneratedMetricForNewCode()) == null) {
- Measure measure = new Measure(getGeneratedMetricForNewCode());
- boolean hasValue = false;
- /* TODO remove this magic number */
- for (int periodIndex = 1; periodIndex <= 5; periodIndex++) {
- Long elements = countElementsForNewCode(context, periodIndex);
-
- if (elements != null && elements > 0L) {
- long coveredElements = countCoveredElementsForNewCode(context, periodIndex);
- measure.setVariation(periodIndex, calculateCoverage(coveredElements, elements));
- hasValue = true;
- }
- }
- if (hasValue) {
- context.saveMeasure(measure);
- }
- }
- }
-
- private static double calculateCoverage(final long coveredLines, final long lines) {
- return (100.0 * coveredLines) / lines;
- }
-
- protected abstract Metric getGeneratedMetric();
-
- protected abstract Long countElements(DecoratorContext context);
-
- protected abstract long countCoveredElements(DecoratorContext context);
-
- protected abstract Metric getGeneratedMetricForNewCode();
-
- protected abstract Long countElementsForNewCode(DecoratorContext context, int periodIndex);
-
- protected abstract long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex);
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import java.util.Collection;
-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 org.sonar.batch.sensor.coverage.CoverageConstants;
-
-public final class BranchCoverageDecorator extends AbstractCoverageDecorator {
-
- @DependsUpon
- public Collection<Metric> dependsUponMetrics() {
- return CoverageConstants.BRANCH_COVERAGE_METRICS;
- }
-
- @Override
- protected Metric getGeneratedMetric() {
- return CoreMetrics.BRANCH_COVERAGE;
- }
-
- @Override
- protected Long countElements(DecoratorContext context) {
- return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER), 0L);
- }
-
- @Override
- 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;
- }
-
- @Override
- protected Metric getGeneratedMetricForNewCode() {
- return CoreMetrics.NEW_BRANCH_COVERAGE;
- }
-
- @Override
- protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
- return MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER), periodIndex);
- }
-
- @Override
- 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;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import java.util.Collection;
-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 org.sonar.batch.sensor.coverage.CoverageConstants;
-
-public final class CoverageDecorator extends AbstractCoverageDecorator {
-
- @DependsUpon
- public Collection<Metric> usedMetrics() {
- return CoverageConstants.COVERAGE_METRICS;
- }
-
- @Override
- protected Metric getGeneratedMetric() {
- return CoreMetrics.COVERAGE;
- }
-
- @Override
- protected Long countElements(DecoratorContext 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;
- }
-
- @Override
- 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);
- 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) {
- return null;
- }
-
- long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER), periodIndex, 0L);
-
- return newLinesToCover + newConditionsToCover;
- }
-
- @Override
- protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
- long newLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_LINES_TO_COVER), periodIndex, 0L);
- 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;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import com.google.common.collect.ImmutableList;
-import java.util.List;
-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;
-
-public final class ItBranchCoverageDecorator extends AbstractCoverageDecorator {
-
- @DependsUpon
- public List<Metric> dependsUponMetrics() {
- return ImmutableList.<Metric>of(CoreMetrics.IT_UNCOVERED_CONDITIONS, CoreMetrics.IT_CONDITIONS_TO_COVER,
- CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS, CoreMetrics.NEW_IT_CONDITIONS_TO_COVER);
- }
-
- @Override
- protected Metric getGeneratedMetric() {
- return CoreMetrics.IT_BRANCH_COVERAGE;
- }
-
- @Override
- protected Long countElements(DecoratorContext context) {
- return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER), 0L);
- }
-
- @Override
- 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;
- }
-
- @Override
- protected Metric getGeneratedMetricForNewCode() {
- return CoreMetrics.NEW_IT_BRANCH_COVERAGE;
- }
-
- @Override
- protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
- return MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER), periodIndex);
- }
-
- @Override
- 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;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import com.google.common.collect.ImmutableList;
-import java.util.Collection;
-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;
-
-public final class ItCoverageDecorator extends AbstractCoverageDecorator {
-
- @DependsUpon
- public Collection<Metric> usedMetrics() {
- return ImmutableList.<Metric>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);
- }
-
- @Override
- protected Metric getGeneratedMetric() {
- return CoreMetrics.IT_COVERAGE;
- }
-
- @Override
- 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;
- }
-
- @Override
- 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);
- 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) {
- return null;
- }
-
- long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER), periodIndex, 0L);
- return newLinesToCover + newConditionsToCover;
- }
-
- @Override
- protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
- long newLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_LINES_TO_COVER), periodIndex, 0L);
- 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;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import com.google.common.collect.ImmutableList;
-import java.util.List;
-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;
-
-public final class ItLineCoverageDecorator extends AbstractCoverageDecorator {
-
- @DependsUpon
- public List<Metric> dependsUponMetrics() {
- return ImmutableList.<Metric>of(CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_LINES,
- CoreMetrics.NEW_IT_LINES_TO_COVER);
- }
-
- @Override
- protected Metric getGeneratedMetric() {
- return CoreMetrics.IT_LINE_COVERAGE;
- }
-
- @Override
- protected Long countElements(DecoratorContext context) {
- return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER), 0L);
- }
-
- @Override
- 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;
- }
-
- @Override
- protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
- return MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_LINES_TO_COVER), periodIndex);
- }
-
- @Override
- 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;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import java.util.Collection;
-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 org.sonar.batch.sensor.coverage.CoverageConstants;
-
-public final class LineCoverageDecorator extends AbstractCoverageDecorator {
-
- @DependsUpon
- public Collection<Metric> dependsUponMetrics() {
- return CoverageConstants.LINE_COVERAGE_METRICS;
- }
-
- @Override
- protected Metric getGeneratedMetric() {
- return CoreMetrics.LINE_COVERAGE;
- }
-
- @Override
- protected Long countElements(DecoratorContext context) {
- return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.LINES_TO_COVER), 0L);
- }
-
- @Override
- 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;
- }
-
- @Override
- protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
- return MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_LINES_TO_COVER), periodIndex);
- }
-
- @Override
- 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;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import com.google.common.collect.ImmutableList;
-import java.util.List;
-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;
-
-public final class OverallBranchCoverageDecorator extends AbstractCoverageDecorator {
-
- @DependsUpon
- public List<Metric> dependsUponMetrics() {
- return ImmutableList.<Metric>of(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, CoreMetrics.OVERALL_CONDITIONS_TO_COVER,
- CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS, CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER);
- }
-
- @Override
- protected Metric getGeneratedMetric() {
- return CoreMetrics.OVERALL_BRANCH_COVERAGE;
- }
-
- @Override
- protected Long countElements(DecoratorContext context) {
- return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER), 0L);
- }
-
- @Override
- protected long countCoveredElements(DecoratorContext context) {
- long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS), 0L);
- long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER), 0L);
-
- return conditions - uncoveredConditions;
- }
-
- @Override
- protected Metric getGeneratedMetricForNewCode() {
- return CoreMetrics.NEW_OVERALL_BRANCH_COVERAGE;
- }
-
- @Override
- protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
- return MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER), periodIndex);
- }
-
- @Override
- protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
- long uncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS), periodIndex, 0L);
- long conditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER), periodIndex, 0L);
-
- return conditions - uncoveredConditions;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import com.google.common.collect.ImmutableList;
-import java.util.Collection;
-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;
-
-public final class OverallCoverageDecorator extends AbstractCoverageDecorator {
-
- @DependsUpon
- public Collection<Metric> usedMetrics() {
- return ImmutableList.<Metric>of(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);
- }
-
- @Override
- protected Metric getGeneratedMetric() {
- return CoreMetrics.OVERALL_COVERAGE;
- }
-
- @Override
- protected Long countElements(DecoratorContext context) {
- long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER), 0L);
- long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER), 0L);
-
- return lines + conditions;
- }
-
- @Override
- protected long countCoveredElements(DecoratorContext context) {
- long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_LINES), 0L);
- long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER), 0L);
- long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS), 0L);
- long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER), 0L);
-
- return lines + conditions - uncoveredConditions - uncoveredLines;
- }
-
- @Override
- protected Metric getGeneratedMetricForNewCode() {
- return CoreMetrics.NEW_OVERALL_COVERAGE;
- }
-
- @Override
- protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
- Long newLinesToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_LINES_TO_COVER), periodIndex);
- if (newLinesToCover == null) {
- return null;
- }
-
- long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER), periodIndex, 0L);
-
- return newLinesToCover + newConditionsToCover;
- }
-
- @Override
- protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
- long newLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_LINES_TO_COVER), periodIndex, 0L);
- long newUncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_UNCOVERED_LINES), periodIndex, 0L);
- long newUncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS), periodIndex, 0L);
- long newConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER), periodIndex, 0L);
-
- return newLines + newConditions - newUncoveredConditions - newUncoveredLines;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import com.google.common.collect.ImmutableList;
-import java.util.List;
-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;
-
-public final class OverallLineCoverageDecorator extends AbstractCoverageDecorator {
-
- @DependsUpon
- public List<Metric> dependsUponMetrics() {
- return ImmutableList.<Metric>of(CoreMetrics.OVERALL_UNCOVERED_LINES, CoreMetrics.OVERALL_LINES_TO_COVER, CoreMetrics.NEW_OVERALL_UNCOVERED_LINES,
- CoreMetrics.NEW_OVERALL_LINES_TO_COVER);
- }
-
- @Override
- protected Metric getGeneratedMetric() {
- return CoreMetrics.OVERALL_LINE_COVERAGE;
- }
-
- @Override
- protected Long countElements(DecoratorContext context) {
- return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER), 0L);
- }
-
- @Override
- protected long countCoveredElements(DecoratorContext context) {
- long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_LINES), 0L);
- long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER), 0L);
-
- return lines - uncoveredLines;
- }
-
- @Override
- protected Metric getGeneratedMetricForNewCode() {
- return CoreMetrics.NEW_OVERALL_LINE_COVERAGE;
- }
-
- @Override
- protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
- return MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_LINES_TO_COVER), periodIndex);
- }
-
- @Override
- protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
- long uncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_UNCOVERED_LINES), periodIndex, 0L);
- long lines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_LINES_TO_COVER), periodIndex, 0L);
-
- return lines - uncoveredLines;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Scopes;
-
-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 BranchCoverageDecoratorTest {
- private final BranchCoverageDecorator decorator = new BranchCoverageDecorator();
- private final Project resource = mock(Project.class);
-
- @Before
- public void setUp() {
- when(resource.getScope()).thenReturn(Scopes.PROJECT);
- when(resource.getQualifier()).thenReturn(Qualifiers.PROJECT);
- }
-
- @Test
- public void shouldSaveBranchCoverage() {
- DecoratorContext context = mockContext(20, 15);
-
- decorator.decorate(resource, context);
-
- verify(context).saveMeasure(CoreMetrics.BRANCH_COVERAGE, 25.0);
- }
-
- @Test
- public void shouldNotSaveBranchCoverageIfMissingConditions() {
- DecoratorContext context = mock(DecoratorContext.class);
-
- decorator.decorate(resource, context);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.BRANCH_COVERAGE), anyDouble());
- }
-
- private static DecoratorContext mockContext(int conditions, int uncoveredConditions) {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.CONDITIONS_TO_COVER, (double) conditions));
- when(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.UNCOVERED_CONDITIONS, (double) uncoveredConditions));
- return context;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import java.util.Collection;
-import org.junit.Before;
-import org.junit.Test;
-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 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.when;
-
-public class CoverageDecoratorTest {
- private CoverageDecorator decorator;
- private final Project project = mock(Project.class);
-
- @Before
- public void before() {
- when(project.getScope()).thenReturn(Scopes.PROJECT);
- decorator = new CoverageDecorator();
- }
-
- @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 coverage() {
- DecoratorContext context = mockContext(50, 40, 10, 8);
-
- decorator.decorate(project, context);
-
- // (50-40 covered lines + 10-8 covered conditions) / (50 lines + 10 conditions)
- verify(context).saveMeasure(CoreMetrics.COVERAGE, 20.0);
- }
-
- @Test
- public void coverageCanBe0() {
- DecoratorContext context = mockContext(50, 50, 5, 5);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.COVERAGE, 0.0);
- }
-
- @Test
- public void coverageCanBe100() {
- DecoratorContext context = mockContext(50, 0, 5, 0);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.COVERAGE, 100.0);
- }
-
- @Test
- public void noCoverageIfNoElements() {
- DecoratorContext context = mock(DecoratorContext.class);
-
- decorator.decorate(project, context);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.COVERAGE), anyDouble());
- }
-
- @Test
- public void should_count_elements_for_new_code() {
- Measure newLines = measureWithVariation(1, 100.0);
- Measure newConditions = measureWithVariation(1, 1.0);
- DecoratorContext context = mockNewContext(newLines, null, null, newConditions);
-
- long count = decorator.countElementsForNewCode(context, 1);
-
- assertThat(count).isEqualTo(101).isEqualTo(100 + 1);
- }
-
- @Test
- public void should_count_covered_elements_for_new_code() {
- Measure newLines = measureWithVariation(1, 100.0);
- Measure newUncoveredConditions = measureWithVariation(1, 10.0);
- Measure newUncoveredLines = measureWithVariation(1, 5.0);
- Measure newConditions = measureWithVariation(1, 1.0);
- DecoratorContext context = mockNewContext(newLines, newUncoveredConditions, newUncoveredLines, newConditions);
-
- long count = decorator.countCoveredElementsForNewCode(context, 1);
-
- assertThat(count).isEqualTo(86).isEqualTo(100 + 1 - 10 - 5);
- }
-
- private static DecoratorContext mockContext(int lines, int uncoveredLines, int conditions, int uncoveredConditions) {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.LINES_TO_COVER, (double) lines));
- when(context.getMeasure(CoreMetrics.UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.UNCOVERED_LINES, (double) uncoveredLines));
- when(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.CONDITIONS_TO_COVER, (double) conditions));
- when(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.UNCOVERED_CONDITIONS, (double) uncoveredConditions));
- return context;
- }
-
- private static DecoratorContext mockNewContext(Measure newLines, Measure newUncoveredConditions, Measure newUncoveredLines, Measure newConditions) {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.NEW_LINES_TO_COVER)).thenReturn(newLines);
- when(context.getMeasure(CoreMetrics.NEW_UNCOVERED_LINES)).thenReturn(newUncoveredLines);
- when(context.getMeasure(CoreMetrics.NEW_UNCOVERED_CONDITIONS)).thenReturn(newUncoveredConditions);
- when(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER)).thenReturn(newConditions);
- return context;
- }
-
- private static Measure measureWithVariation(int period, double variation) {
- Measure measure = mock(Measure.class);
- when(measure.getVariation(period)).thenReturn(variation);
- return measure;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Scopes;
-
-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 ItBranchCoverageDecoratorTest {
- private final ItBranchCoverageDecorator decorator = new ItBranchCoverageDecorator();
- private final Project resource = mock(Project.class);
-
- @Before
- public void setUp() {
- when(resource.getScope()).thenReturn(Scopes.PROJECT);
- when(resource.getQualifier()).thenReturn(Qualifiers.PROJECT);
- }
-
- @Test
- public void shouldSaveBranchCoverage() {
- DecoratorContext context = mockContext(20, 15);
-
- decorator.decorate(resource, context);
-
- verify(context).saveMeasure(CoreMetrics.IT_BRANCH_COVERAGE, 25.0);
- }
-
- @Test
- public void shouldNotSaveBranchCoverageIfMissingConditions() {
- DecoratorContext context = mock(DecoratorContext.class);
-
- decorator.decorate(resource, context);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.IT_BRANCH_COVERAGE), anyDouble());
- }
-
- private static DecoratorContext mockContext(int conditions, int uncoveredConditions) {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.IT_CONDITIONS_TO_COVER, (double) conditions));
- when(context.getMeasure(CoreMetrics.IT_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.IT_UNCOVERED_CONDITIONS, (double) uncoveredConditions));
- return context;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import java.util.Collection;
-import org.junit.Before;
-import org.junit.Test;
-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 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.when;
-
-public class ItCoverageDecoratorTest {
- private final ItCoverageDecorator decorator = new ItCoverageDecorator();
- private final Project project = mock(Project.class);
-
- @Before
- public void before() {
- 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 coverage() {
- DecoratorContext context = mockContext(50, 40, 10, 8);
-
- decorator.decorate(project, context);
-
- // (50-40 covered lines + 10-8 covered conditions) / (50 lines + 10 conditions)
- verify(context).saveMeasure(CoreMetrics.IT_COVERAGE, 20.0);
- }
-
- @Test
- public void coverageCanBe0() {
- DecoratorContext context = mockContext(50, 50, 5, 5);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.IT_COVERAGE, 0.0);
- }
-
- @Test
- public void coverageCanBe100() {
- DecoratorContext context = mockContext(50, 0, 5, 0);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.IT_COVERAGE, 100.0);
- }
-
- @Test
- public void noCoverageIfNoElements() {
- DecoratorContext context = mock(DecoratorContext.class);
-
- decorator.decorate(project, context);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.IT_COVERAGE), anyDouble());
- }
-
- @Test
- public void should_count_elements_for_new_code() {
- Measure newLines = measureWithVariation(1, 100.0);
- Measure newConditions = measureWithVariation(1, 1.0);
- DecoratorContext context = mockNewContext(newLines, null, null, newConditions);
-
- long count = decorator.countElementsForNewCode(context, 1);
-
- assertThat(count).isEqualTo(101).isEqualTo(100 + 1);
- }
-
- @Test
- public void should_count_covered_elements_for_new_code() {
- Measure newLines = measureWithVariation(1, 100.0);
- Measure newUncoveredConditions = measureWithVariation(1, 10.0);
- Measure newUncoveredLines = measureWithVariation(1, 5.0);
- Measure newConditions = measureWithVariation(1, 1.0);
- DecoratorContext context = mockNewContext(newLines, newUncoveredConditions, newUncoveredLines, newConditions);
-
- long count = decorator.countCoveredElementsForNewCode(context, 1);
-
- assertThat(count).isEqualTo(86).isEqualTo(100 + 1 - 10 - 5);
- }
-
- private static DecoratorContext mockContext(int lines, int uncoveredLines, int conditions, int uncoveredConditions) {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.IT_LINES_TO_COVER, (double) lines));
- when(context.getMeasure(CoreMetrics.IT_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.IT_UNCOVERED_LINES, (double) uncoveredLines));
- when(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.IT_CONDITIONS_TO_COVER, (double) conditions));
- when(context.getMeasure(CoreMetrics.IT_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.IT_UNCOVERED_CONDITIONS, (double) uncoveredConditions));
- return context;
- }
-
- private static DecoratorContext mockNewContext(Measure newLines, Measure newUncoveredConditions, Measure newUncoveredLines, Measure newConditions) {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.NEW_IT_LINES_TO_COVER)).thenReturn(newLines);
- when(context.getMeasure(CoreMetrics.NEW_IT_UNCOVERED_LINES)).thenReturn(newUncoveredLines);
- when(context.getMeasure(CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS)).thenReturn(newUncoveredConditions);
- when(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER)).thenReturn(newConditions);
- return context;
- }
-
- private static Measure measureWithVariation(int period, double variation) {
- Measure measure = mock(Measure.class);
- when(measure.getVariation(period)).thenReturn(variation);
- return measure;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-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 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.when;
-
-public class ItLineCoverageDecoratorTest {
- private final ItLineCoverageDecorator decorator = new ItLineCoverageDecorator();
- private final Project project = mock(Project.class);
-
- @Before
- public void before() {
- when(project.getScope()).thenReturn(Scopes.PROJECT);
- }
-
- @Test
- public void should_depend_on_coverage_metrics() {
- List<Metric> metrics = decorator.dependsUponMetrics();
-
- assertThat(metrics).containsOnly(CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_LINES, CoreMetrics.NEW_IT_LINES_TO_COVER);
- }
-
- @Test
- public void lineCoverage() {
- DecoratorContext context = mockContext(50, 10);
-
- decorator.decorate(project, context);
-
- // 50-10 covered lines / 50 lines
- verify(context).saveMeasure(CoreMetrics.IT_LINE_COVERAGE, 80.0);
- }
-
- @Test
- public void zeroCoveredLines() {
- DecoratorContext context = mockContext(50, 50);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.IT_LINE_COVERAGE, 0.0);
- }
-
- @Test
- public void allCoveredLines() {
- DecoratorContext context = mockContext(50, 00);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.IT_LINE_COVERAGE, 100.0);
- }
-
- @Test
- public void noLineCoverageIfNoLines() {
- DecoratorContext context = mock(DecoratorContext.class);
-
- decorator.decorate(project, context);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.IT_LINE_COVERAGE), anyDouble());
- }
-
- private static DecoratorContext mockContext(int lines, int uncoveredLines) {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.IT_LINES_TO_COVER, (double) lines));
- when(context.getMeasure(CoreMetrics.IT_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.IT_UNCOVERED_LINES, (double) uncoveredLines));
- return context;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Scopes;
-
-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.when;
-
-public class LineCoverageDecoratorTest {
-
- private LineCoverageDecorator decorator;
- private final Project project = mock(Project.class);
-
- @Before
- public void before() {
- when(project.getScope()).thenReturn(Scopes.PROJECT);
- decorator = new LineCoverageDecorator();
- }
-
- @Test
- public void should_depend_on_coverage_metrics() {
- assertThat(decorator.dependsUponMetrics()).containsOnly(CoreMetrics.UNCOVERED_LINES, CoreMetrics.LINES_TO_COVER, CoreMetrics.NEW_UNCOVERED_LINES,
- CoreMetrics.NEW_LINES_TO_COVER);
- }
-
- @Test
- public void lineCoverage() {
- DecoratorContext context = mockContext(50, 10);
-
- decorator.decorate(project, context);
-
- // 50-10 covered lines / 50 lines
- verify(context).saveMeasure(CoreMetrics.LINE_COVERAGE, 80.0);
- }
-
- @Test
- public void zeroCoveredLines() {
- DecoratorContext context = mockContext(50, 50);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.LINE_COVERAGE, 0.0);
- }
-
- @Test
- public void allCoveredLines() {
- DecoratorContext context = mockContext(50, 00);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.LINE_COVERAGE, 100.0);
- }
-
- @Test
- public void noLineCoverageIfNoLines() {
- DecoratorContext context = mock(DecoratorContext.class);
-
- decorator.decorate(project, context);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.LINE_COVERAGE), anyDouble());
- }
-
- private static DecoratorContext mockContext(int lines, int uncoveredLines) {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.LINES_TO_COVER, (double) lines));
- when(context.getMeasure(CoreMetrics.UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.UNCOVERED_LINES, (double) uncoveredLines));
- return context;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Scopes;
-
-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 OverallBranchCoverageDecoratorTest {
- private final OverallBranchCoverageDecorator decorator = new OverallBranchCoverageDecorator();
- private final Project resource = mock(Project.class);
-
- @Before
- public void setUp() {
- when(resource.getScope()).thenReturn(Scopes.PROJECT);
- when(resource.getQualifier()).thenReturn(Qualifiers.PROJECT);
- }
-
- @Test
- public void shouldSaveBranchCoverage() {
- DecoratorContext context = mockContext(20, 15);
-
- decorator.decorate(resource, context);
-
- verify(context).saveMeasure(CoreMetrics.OVERALL_BRANCH_COVERAGE, 25.0);
- }
-
- @Test
- public void shouldNotSaveBranchCoverageIfMissingConditions() {
- DecoratorContext context = mock(DecoratorContext.class);
-
- decorator.decorate(resource, context);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.OVERALL_BRANCH_COVERAGE), anyDouble());
- }
-
- private static DecoratorContext mockContext(int conditions, int uncoveredConditions) {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER, (double) conditions));
- when(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, (double) uncoveredConditions));
- return context;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import java.util.Collection;
-import org.junit.Before;
-import org.junit.Test;
-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 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.when;
-
-public class OverallCoverageDecoratorTest {
- private final OverallCoverageDecorator decorator = new OverallCoverageDecorator();
- private final Project project = mock(Project.class);
-
- @Before
- public void before() {
- when(project.getScope()).thenReturn(Scopes.PROJECT);
- }
-
- @Test
- public void should_use_metrics() {
- 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);
- }
-
- @Test
- public void coverage() {
- DecoratorContext context = mockContext(50, 40, 10, 8);
-
- decorator.decorate(project, context);
-
- // (50-40 covered lines + 10-8 covered conditions) / (50 lines + 10 conditions)
- verify(context).saveMeasure(CoreMetrics.OVERALL_COVERAGE, 20.0);
- }
-
- @Test
- public void coverageCanBe0() {
- DecoratorContext context = mockContext(50, 50, 5, 5);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.OVERALL_COVERAGE, 0.0);
- }
-
- @Test
- public void coverageCanBe100() {
- DecoratorContext context = mockContext(50, 0, 5, 0);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.OVERALL_COVERAGE, 100.0);
- }
-
- @Test
- public void noCoverageIfNoElements() {
- DecoratorContext context = mock(DecoratorContext.class);
-
- decorator.decorate(project, context);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.OVERALL_COVERAGE), anyDouble());
- }
-
- @Test
- public void should_count_elements_for_new_code() {
- Measure newLines = measureWithVariation(1, 100.0);
- Measure newConditions = measureWithVariation(1, 1.0);
- DecoratorContext context = mockNewContext(newLines, null, null, newConditions);
-
- long count = decorator.countElementsForNewCode(context, 1);
-
- assertThat(count).isEqualTo(101).isEqualTo(100 + 1);
- }
-
- @Test
- public void should_count_covered_elements_for_new_code() {
- Measure newLines = measureWithVariation(1, 100.0);
- Measure newUncoveredConditions = measureWithVariation(1, 10.0);
- Measure newUncoveredLines = measureWithVariation(1, 5.0);
- Measure newConditions = measureWithVariation(1, 1.0);
- DecoratorContext context = mockNewContext(newLines, newUncoveredConditions, newUncoveredLines, newConditions);
-
- long count = decorator.countCoveredElementsForNewCode(context, 1);
-
- assertThat(count).isEqualTo(86).isEqualTo(100 + 1 - 10 - 5);
- }
-
- private static DecoratorContext mockContext(int lines, int uncoveredLines, int conditions, int uncoveredConditions) {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.OVERALL_LINES_TO_COVER, (double) lines));
- when(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.OVERALL_UNCOVERED_LINES, (double) uncoveredLines));
- when(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER, (double) conditions));
- when(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, (double) uncoveredConditions));
- return context;
- }
-
- private static DecoratorContext mockNewContext(Measure newLines, Measure newUncoveredConditions, Measure newUncoveredLines, Measure newConditions) {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.NEW_OVERALL_LINES_TO_COVER)).thenReturn(newLines);
- when(context.getMeasure(CoreMetrics.NEW_OVERALL_UNCOVERED_LINES)).thenReturn(newUncoveredLines);
- when(context.getMeasure(CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS)).thenReturn(newUncoveredConditions);
- when(context.getMeasure(CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER)).thenReturn(newConditions);
- return context;
- }
-
- private static Measure measureWithVariation(int period, double variation) {
- Measure measure = mock(Measure.class);
- when(measure.getVariation(period)).thenReturn(variation);
- return measure;
- }
-}
+++ /dev/null
-/*
- * 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.batch.compute;
-
-import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-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 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.when;
-
-public class OverallLineCoverageDecoratorTest {
- private final OverallLineCoverageDecorator decorator = new OverallLineCoverageDecorator();
- private final Project project = mock(Project.class);
-
- @Before
- public void before() {
- when(project.getScope()).thenReturn(Scopes.PROJECT);
- }
-
- @Test
- public void should_depend_on_coverage_metrics() {
- 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);
- }
-
- @Test
- public void lineCoverage() {
- DecoratorContext context = mockContext(50, 10);
-
- decorator.decorate(project, context);
-
- // 50-10 covered lines / 50 lines
- verify(context).saveMeasure(CoreMetrics.OVERALL_LINE_COVERAGE, 80.0);
- }
-
- @Test
- public void zeroCoveredLines() {
- DecoratorContext context = mockContext(50, 50);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.OVERALL_LINE_COVERAGE, 0.0);
- }
-
- @Test
- public void allCoveredLines() {
- DecoratorContext context = mockContext(50, 00);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.OVERALL_LINE_COVERAGE, 100.0);
- }
-
- @Test
- public void noLineCoverageIfNoLines() {
- DecoratorContext context = mock(DecoratorContext.class);
-
- decorator.decorate(project, context);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.OVERALL_LINE_COVERAGE), anyDouble());
- }
-
- private static DecoratorContext mockContext(int lines, int uncoveredLines) {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.OVERALL_LINES_TO_COVER, (double) lines));
- when(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.OVERALL_UNCOVERED_LINES, (double) uncoveredLines));
- return context;
- }
-}