From 74372f4f92913383931e1742ddaf071216edfcfd Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 30 Jun 2015 16:42:29 +0200 Subject: [PATCH] remove dead code (AbstractDivisionDecorator) --- .../api/batch/AbstractDivisionDecorator.java | 94 -------------- .../batch/AbstractDivisionDecoratorTest.java | 116 ------------------ 2 files changed, 210 deletions(-) delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractDivisionDecorator.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractDivisionDecoratorTest.java diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractDivisionDecorator.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractDivisionDecorator.java deleted file mode 100644 index fb624c832c8..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractDivisionDecorator.java +++ /dev/null @@ -1,94 +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.api.batch; - -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 java.util.Arrays; -import java.util.List; - -/** - * A pre-implementation to decorate metrics that are the result of a division - * - * @since 1.10 - */ -public abstract class AbstractDivisionDecorator implements Decorator { - - protected abstract Metric getQuotientMetric(); - - protected abstract Metric getDivisorMetric(); - - protected abstract Metric getDividendMetric(); - - /** - * Used to define upstream dependencies - */ - @DependsUpon - public List dependsUponMetrics() { - return Arrays.asList(getDividendMetric(), getDivisorMetric()); - } - - /** - * Used to define downstream dependencies - */ - @DependedUpon - public Metric generatesMetric() { - return getQuotientMetric(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean shouldExecuteOnProject(Project project) { - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public void decorate(Resource resource, DecoratorContext context) { - if (!shouldDecorateResource(context)) { - return; - } - Measure dividend = context.getMeasure(getDividendMetric()); - Measure divisor = context.getMeasure(getDivisorMetric()); - - if (MeasureUtils.hasValue(dividend) && MeasureUtils.hasValue(divisor) && divisor.getValue() > 0.0) { - context.saveMeasure(new Measure(getQuotientMetric(), compute(dividend, divisor, getQuotientMetric().isPercentageType()))); - } - } - - protected boolean shouldDecorateResource(DecoratorContext context) { - return context.getMeasure(getQuotientMetric()) == null; - } - - - protected double compute(Measure dividend, Measure divisor, boolean shouldResultBeInPercent) { - double result = dividend.getValue() / divisor.getValue(); - return shouldResultBeInPercent ? (result * 100) : result; - } - -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractDivisionDecoratorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractDivisionDecoratorTest.java deleted file mode 100644 index d54fa37edd4..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractDivisionDecoratorTest.java +++ /dev/null @@ -1,116 +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.api.batch; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; - -import org.junit.Test; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Resource; -import org.sonar.api.test.IsMeasure; - -public class AbstractDivisionDecoratorTest { - - @Test - public void divide() { - AbstractDivisionDecorator decorator = createDecorator(); - - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.CLASSES)).thenReturn(new Measure(CoreMetrics.CLASSES, 20.0)); - when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 120.0)); - - decorator.decorate(mock(Resource.class), context); - - verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.CLASS_COMPLEXITY, 6.0))); - } - - @Test - public void nothingWhenMissingData() { - AbstractDivisionDecorator decorator = createDecorator(); - - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.CLASSES)).thenReturn(new Measure(CoreMetrics.CLASSES, 20.0)); - - decorator.decorate(mock(Resource.class), context); - - verify(context, never()).saveMeasure(any(Measure.class)); - } - - @Test - public void zeroWhenDivisorIsZero() { - AbstractDivisionDecorator decorator = createDecorator(); - - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.CLASSES)).thenReturn(new Measure(CoreMetrics.CLASSES, 20.0)); - when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 0.0)); - - decorator.decorate(mock(Resource.class), context); - - verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.CLASS_COMPLEXITY, 0.0))); - } - - - @Test - public void doNotOverrideExistingMeasure() { - AbstractDivisionDecorator decorator = createDecorator(); - - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.CLASSES)).thenReturn(new Measure(CoreMetrics.CLASSES, 20.0)); - when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 120.0)); - when(context.getMeasure(CoreMetrics.CLASS_COMPLEXITY)).thenReturn(new Measure(CoreMetrics.CLASS_COMPLEXITY, 3.0)); - - decorator.decorate(mock(Resource.class), context); - - verify(context, never()).saveMeasure(any(Measure.class)); - } - - - @Test - public void defineDependencies() { - AbstractDivisionDecorator decorator = createDecorator(); - assertThat(decorator.dependsUponMetrics()).contains(CoreMetrics.CLASSES); - assertThat(decorator.dependsUponMetrics()).contains(CoreMetrics.COMPLEXITY); - assertThat(decorator.generatesMetric()).isEqualTo(CoreMetrics.CLASS_COMPLEXITY); - } - - - private AbstractDivisionDecorator createDecorator() { - AbstractDivisionDecorator decorator = new AbstractDivisionDecorator() { - @Override - protected Metric getQuotientMetric() { - return CoreMetrics.CLASS_COMPLEXITY; - } - - @Override - protected Metric getDivisorMetric() { - return CoreMetrics.CLASSES; - } - - @Override - protected Metric getDividendMetric() { - return CoreMetrics.COMPLEXITY; - } - }; - return decorator; - } -} -- 2.39.5