diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-07-20 09:20:30 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-07-21 17:31:54 +0200 |
commit | 245d9e1719ef6b3cc4d848d7c993f27c79b138fe (patch) | |
tree | 2f4ca9d38a8509171546cde559405f176bdefb51 /sonar-batch/src | |
parent | d9ac0b473f325cc94db3a800a1dcbe9c681def7d (diff) | |
download | sonarqube-245d9e1719ef6b3cc4d848d7c993f27c79b138fe.tar.gz sonarqube-245d9e1719ef6b3cc4d848d7c993f27c79b138fe.zip |
SONAR-6681 Remove UnitTestDecorator form the batch
Diffstat (limited to 'sonar-batch/src')
4 files changed, 1 insertions, 185 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java index e372cabd17c..40ece5d78d0 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java @@ -24,7 +24,6 @@ import java.util.Collection; import java.util.List; import org.sonar.batch.compute.DirectoriesDecorator; import org.sonar.batch.compute.FilesDecorator; -import org.sonar.batch.compute.UnitTestDecorator; import org.sonar.batch.cpd.CpdComponents; import org.sonar.batch.issue.tracking.IssueTracking; import org.sonar.batch.scan.report.ConsoleReport; @@ -67,7 +66,6 @@ public class BatchComponents { RuleNameProvider.class, // to be moved to compute engine - UnitTestDecorator.class, DirectoriesDecorator.class, FilesDecorator.class ); diff --git a/sonar-batch/src/main/java/org/sonar/batch/compute/UnitTestDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/compute/UnitTestDecorator.java deleted file mode 100644 index 3f5d641af0c..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/compute/UnitTestDecorator.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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 java.util.List; -import org.sonar.api.batch.Decorator; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependedUpon; -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; -import org.sonar.api.resources.ResourceUtils; - -public class UnitTestDecorator implements Decorator { - - @DependedUpon - public List<Metric> generatesMetrics() { - return Arrays.<Metric>asList(CoreMetrics.TEST_EXECUTION_TIME, CoreMetrics.TESTS, CoreMetrics.TEST_ERRORS, CoreMetrics.TEST_FAILURES, CoreMetrics.TEST_SUCCESS_DENSITY); - } - - @Override - public boolean shouldExecuteOnProject(Project project) { - return !Project.AnalysisType.STATIC.equals(project.getAnalysisType()); - } - - public boolean shouldDecorateResource(Resource resource) { - return ResourceUtils.isUnitTestFile(resource) || !ResourceUtils.isEntity(resource); - } - - @Override - public void decorate(Resource resource, DecoratorContext context) { - if (shouldDecorateResource(resource)) { - sumChildren(context, CoreMetrics.TEST_EXECUTION_TIME); - sumChildren(context, CoreMetrics.SKIPPED_TESTS); - Double tests = sumChildren(context, CoreMetrics.TESTS); - Double errors = sumChildren(context, CoreMetrics.TEST_ERRORS); - Double failures = sumChildren(context, CoreMetrics.TEST_FAILURES); - - if (isPositive(tests, true) && isPositive(errors, false) && isPositive(failures, false)) { - Double errorsAndFailuresRatio = (errors + failures) * 100.0 / tests; - context.saveMeasure(CoreMetrics.TEST_SUCCESS_DENSITY, 100.0 - errorsAndFailuresRatio); - } - } - } - - private boolean isPositive(Double d, boolean strict) { - return d != null && (strict ? d > 0.0 : d >= 0.0); - } - - private Double sumChildren(DecoratorContext jobContext, Metric metric) { - Collection<Measure> childrenMeasures = jobContext.getChildrenMeasures(metric); - if (childrenMeasures != null && !childrenMeasures.isEmpty()) { - Double sum = 0.0; - boolean hasChildrenMeasures = false; - for (Measure measure : childrenMeasures) { - if (MeasureUtils.hasValue(measure)) { - sum += measure.getValue(); - hasChildrenMeasures = true; - } - } - if (hasChildrenMeasures) { - jobContext.saveMeasure(metric, sum); - return sum; - } - } - return null; - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/compute/UnitTestDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/compute/UnitTestDecoratorTest.java deleted file mode 100644 index eb9bd93a4d1..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/compute/UnitTestDecoratorTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 org.hamcrest.Matchers; -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 static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.doubleThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class UnitTestDecoratorTest { - - private UnitTestDecorator decorator; - private DecoratorContext context; - - @Before - public void setUp() { - decorator = new UnitTestDecorator(); - context = mock(DecoratorContext.class); - } - - @Test - public void generatesMetrics() { - assertThat(decorator.generatesMetrics()).hasSize(5); - } - - @Test - public void doNotDecorateStaticAnalysis() { - Project project = mock(Project.class); - when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC); - assertThat(decorator.shouldExecuteOnProject(project)).isFalse(); - - when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC); - assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); - } - - @Test - public void shouldSumChildren() { - Project project = mock(Project.class); - mockChildrenMeasures(CoreMetrics.TESTS, 3.0); - mockChildrenMeasures(CoreMetrics.TEST_ERRORS, 1.0); - mockChildrenMeasures(CoreMetrics.TEST_FAILURES, 1.0); - mockChildrenMeasures(CoreMetrics.SKIPPED_TESTS, 1.0); - mockChildrenMeasures(CoreMetrics.TEST_EXECUTION_TIME, 1.0); - - decorator.decorate(project, context); - - verify(context).saveMeasure(eq(CoreMetrics.TESTS), eq(6.0)); - verify(context).saveMeasure(eq(CoreMetrics.TEST_ERRORS), eq(2.0)); - verify(context).saveMeasure(eq(CoreMetrics.TEST_FAILURES), eq(2.0)); - verify(context).saveMeasure(eq(CoreMetrics.SKIPPED_TESTS), eq(2.0)); - verify(context).saveMeasure(eq(CoreMetrics.TEST_EXECUTION_TIME), eq(2.0)); - verify(context).saveMeasure(eq(CoreMetrics.TEST_SUCCESS_DENSITY), doubleThat(Matchers.closeTo(33.3, 0.1))); - } - - private void mockChildrenMeasures(Metric metric, double value) { - when(context.getChildrenMeasures(metric)).thenReturn(Arrays.asList(new Measure(metric, value), new Measure(metric, value))); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java index 001673e63f8..895e95facad 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java @@ -67,7 +67,7 @@ public class MeasuresMediumTest { .newScanTask(new File(tmpDir, "sonar-project.properties")) .start(); - assertThat(result.allMeasures()).hasSize(37); + assertThat(result.allMeasures()).hasSize(25); } @Test |