diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2014-02-03 15:20:42 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2014-02-03 15:20:53 +0100 |
commit | 5adb3998b2e33eb2bf454ba1a7b98927f4082ed3 (patch) | |
tree | 64bc88d0e16ca32003c1b1412f8ea9745d745abb /sonar-deprecated/src | |
parent | 3ab193022b286c35bd3d6ef1eaae138e22cc0b16 (diff) | |
download | sonarqube-5adb3998b2e33eb2bf454ba1a7b98927f4082ed3.tar.gz sonarqube-5adb3998b2e33eb2bf454ba1a7b98927f4082ed3.zip |
SONAR-926 move deprecated decorators to sonar-deprecated lib
Diffstat (limited to 'sonar-deprecated/src')
8 files changed, 630 insertions, 0 deletions
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractDirectoriesDecorator.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractDirectoriesDecorator.java new file mode 100644 index 00000000000..3ccc4edae81 --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractDirectoriesDecorator.java @@ -0,0 +1,55 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; + +/** + * A pre-implementation to decorate the number of directories + * + * @since 1.10 + * @deprecated since 2.2, the number of directories is automatically calculated by sonar core (see metric formula) + */ +@Deprecated +public abstract class AbstractDirectoriesDecorator implements Decorator { + + + /** + * @param language this will be use to defined whether the decorator should be executed on a project + */ + public AbstractDirectoriesDecorator(Language language) {//NOSONAR this unused parameter is kept for backward-compatibility of API + } + + /** + * {@inheritDoc} + */ + public boolean shouldExecuteOnProject(Project project) { + return false; + } + + /** + * {@inheritDoc} + */ + public void decorate(Resource resource, DecoratorContext context) { + + } +} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFileComplexityDecorator.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFileComplexityDecorator.java new file mode 100644 index 00000000000..ffd9b09ea3f --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFileComplexityDecorator.java @@ -0,0 +1,89 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.CoreMetrics; +import org.sonar.api.measures.MeasureUtils; +import org.sonar.api.measures.Metric; +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; +import org.sonar.api.resources.ResourceUtils; + +import java.util.Arrays; +import java.util.List; + +/** + * @deprecated since 2.1, a formula has been implemented on the metric, so no need to have decorator anymore + * @since 1.10 + */ +@Deprecated +public abstract class AbstractFileComplexityDecorator implements Decorator { + + private Language language; + + /** + * @param language this will be use to defined whether the decorator should be executed on a project + */ + public AbstractFileComplexityDecorator(Language language) { + this.language = language; + } + + /** + * {@inheritDoc} + */ + public boolean shouldExecuteOnProject(Project project) { + return language.equals(project.getLanguage()); + } + + /** + * Used to define upstream dependencies + */ + @DependsUpon + public List<Metric> dependsUponFileAndComplexityMetrics() { + return Arrays.asList(CoreMetrics.FILES, CoreMetrics.COMPLEXITY); + } + + /** + * Used to define downstream dependencies + */ + @DependedUpon + public Metric generateFileComplexityMetric() { + return CoreMetrics.FILE_COMPLEXITY; + } + + /** + * {@inheritDoc} + */ + public void decorate(Resource resource, DecoratorContext context) { + if (!shouldDecorateResource(resource, context)) { + return; + } + Double files = MeasureUtils.getValue(context.getMeasure(CoreMetrics.FILES), null); + Double complexity = MeasureUtils.getValue(context.getMeasure(CoreMetrics.COMPLEXITY), null); + if (complexity != null && files != null && files > 0.0) { + context.saveMeasure(CoreMetrics.FILE_COMPLEXITY, complexity / files); + } + } + + private boolean shouldDecorateResource(Resource resource, DecoratorContext context) { + return !MeasureUtils.hasValue(context.getMeasure(CoreMetrics.FILE_COMPLEXITY)) && !ResourceUtils.isEntity(resource); + } +} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFilesDecorator.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFilesDecorator.java new file mode 100644 index 00000000000..35d9ba30b9a --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFilesDecorator.java @@ -0,0 +1,55 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; + +/** + * A pre-implementation to decorate the number of files + + * @since 1.10 + * @deprecated since 2.2, the number of files is automatically calculated by sonar core (see metric formula) + */ +@Deprecated +public abstract class AbstractFilesDecorator implements Decorator { + + + /** + * @param language this will be use to defined whether the decorator should be executed on a project + */ + public AbstractFilesDecorator(Language language) { + } + + /** + * {@inheritDoc} + */ + public boolean shouldExecuteOnProject(Project project) { + return false; + } + + /** + * {@inheritDoc} + */ + public void decorate(Resource resource, DecoratorContext context) { + + } +} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDecorator.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDecorator.java new file mode 100644 index 00000000000..d3aeb079633 --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDecorator.java @@ -0,0 +1,88 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.CoreMetrics; +import org.sonar.api.measures.MeasureUtils; +import org.sonar.api.measures.Metric; +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; + +import java.util.Arrays; +import java.util.List; + +/** + * @deprecated since 2.1, a formula has been implemented on the metric, so no need to have decorator anymore + * @since 1.13 + */ +@Deprecated +public abstract class AbstractFunctionComplexityDecorator implements Decorator { + + private Language language; + + /** + * @param language this will be use to defined whether the decorator should be executed on a project + */ + public AbstractFunctionComplexityDecorator(Language language) { + this.language = language; + } + + /** + * {@inheritDoc} + */ + public boolean shouldExecuteOnProject(Project project) { + return language.equals(project.getLanguage()); + } + + /** + * Used to define upstream dependencies + */ + @DependsUpon + public List<Metric> dependsUponFileAndComplexityMetrics() { + return Arrays.asList(CoreMetrics.FUNCTIONS, CoreMetrics.COMPLEXITY); + } + + /** + * Used to define downstream dependencies + */ + @DependedUpon + public Metric generateFileComplexityMetric() { + return CoreMetrics.FUNCTION_COMPLEXITY; + } + + /** + * {@inheritDoc} + */ + public void decorate(Resource resource, DecoratorContext context) { + if (!shouldDecorateResource(resource, context)) { + return; + } + Double functions = MeasureUtils.getValue(context.getMeasure(CoreMetrics.FUNCTIONS), null); + Double complexity = MeasureUtils.getValue(context.getMeasure(CoreMetrics.COMPLEXITY), null); + if (complexity != null && functions != null && functions > 0.0) { + context.saveMeasure(CoreMetrics.FUNCTION_COMPLEXITY, complexity / functions); + } + } + + private boolean shouldDecorateResource(Resource resource, DecoratorContext context) { + return !MeasureUtils.hasValue(context.getMeasure(CoreMetrics.FUNCTION_COMPLEXITY)); + } +} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDistributionDecorator.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDistributionDecorator.java new file mode 100644 index 00000000000..967a3048dec --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractFunctionComplexityDistributionDecorator.java @@ -0,0 +1,83 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.CoreMetrics; +import org.sonar.api.measures.CountDistributionBuilder; +import org.sonar.api.measures.Measure; +import org.sonar.api.measures.Metric; +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; + +/** + * @deprecated since 2.1, a formula has been implemented on the metric, so no need to have decorator anymore + * @since 2.0 + */ +@Deprecated +public abstract class AbstractFunctionComplexityDistributionDecorator implements Decorator { + + private CountDistributionBuilder builder = new CountDistributionBuilder(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION); + private Language language; + + public AbstractFunctionComplexityDistributionDecorator(Language language) { + this.language = language; + } + + @DependedUpon + public Metric generatesMetrics() { + return CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION; + } + + public boolean shouldExecuteOnProject(Project project) { + return language.equals(project.getLanguage()); + } + + public void decorate(Resource resource, DecoratorContext context) { + if (shouldDecorateResource(context)) { + reset(); + saveDistribution(context); + } + } + + private void saveDistribution(DecoratorContext context) { + for (Measure childMeasure : context.getChildrenMeasures(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION)) { + builder.add(childMeasure); + } + + if (!builder.isEmpty()) { + context.saveMeasure(builder.build()); + } + } + + private void reset() { + builder.clear(); + } + + private boolean shouldDecorateResource(DecoratorContext context) { + return context.getMeasure(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION) == null; + } + + @Override + public String toString() { + return getClass().getSimpleName(); + } +} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java new file mode 100644 index 00000000000..a892c8ff1b5 --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java @@ -0,0 +1,84 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.ProjectFileSystem; +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.resources.Resource; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.List; + +/** + * @since 1.10 + * @deprecated since 4.2 Component indexing and source import are done by core and this extension is not used. + */ +@Deprecated +@Phase(name = Phase.Name.PRE) +public abstract class AbstractSourceImporter implements Sensor { + + private Language language; + + public AbstractSourceImporter(Language language) { + this.language = language; + } + + public boolean shouldExecuteOnProject(Project project) { + return false; + } + + public void analyse(Project project, SensorContext context) { + // Do not remove for backward compatibility + } + + protected void onFinished() { + + } + + protected void analyse(ProjectFileSystem fileSystem, SensorContext context) { + // Do not remove for backward compatibility + } + + protected void parseDirs(SensorContext context, List<File> files, List<File> sourceDirs, boolean unitTest, Charset sourcesEncoding) { + // Do not remove for backward compatibility + } + + protected Resource createResource(File file, List<File> sourceDirs, boolean unitTest) { + org.sonar.api.resources.File resource = org.sonar.api.resources.File.fromIOFile(file, sourceDirs); + if (resource != null) { + resource.setLanguage(language); + if (unitTest) { + resource.setQualifier(Qualifiers.UNIT_TEST_FILE); + } + } + return resource; + } + + protected boolean isEnabled(Project project) { + return false; + } + + public Language getLanguage() { + return language; + } +} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractFileComplexityDecoratorTest.java b/sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractFileComplexityDecoratorTest.java new file mode 100644 index 00000000000..8a4d0a9e53e --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractFileComplexityDecoratorTest.java @@ -0,0 +1,88 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.junit.Test; +import static org.mockito.Mockito.*; +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.Resource; + +public class AbstractFileComplexityDecoratorTest { + + @Test + public void calculateFileComplexity() { + + Resource directory = new Directory("fake"); + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 20.0)); + when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 500.0)); + + new AbstractFileComplexityDecorator(Java.INSTANCE) { + }.decorate(directory, context); + + verify(context).saveMeasure(CoreMetrics.FILE_COMPLEXITY, 25.0); + } + + @Test + public void noAverageIfMissingData() { + + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 20.0)); + Resource directory = new Directory("fake"); + + new AbstractFileComplexityDecorator(Java.INSTANCE) { + }.decorate(directory, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.FILE_COMPLEXITY), anyDouble()); + } + + @Test + public void noAverageIfZeroFiles() { + AbstractFileComplexityDecorator decorator = new AbstractFileComplexityDecorator(Java.INSTANCE) { + }; + + Resource directory = new Directory("fake"); + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 0.0)); + when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 500.0)); + + decorator.decorate(directory, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.FILE_COMPLEXITY), anyDouble()); + } + + @Test + public void doNotCalculateOnFiles() { + + Resource file = new File("fake"); + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 1.0)); + when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 25.0)); + + new AbstractFileComplexityDecorator(Java.INSTANCE) { + }.decorate(file, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.FILE_COMPLEXITY), anyDouble()); + } +} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractFunctionComplexityDecoratorTest.java b/sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractFunctionComplexityDecoratorTest.java new file mode 100644 index 00000000000..e2777379fa3 --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractFunctionComplexityDecoratorTest.java @@ -0,0 +1,88 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.junit.Test; +import static org.mockito.Mockito.*; +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.Resource; + +public class AbstractFunctionComplexityDecoratorTest { + + @Test + public void calculateFunctionComplexity() { + + Resource directory = new Directory("fake"); + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 200.0)); + when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 500.0)); + + new AbstractFunctionComplexityDecorator(Java.INSTANCE) { + }.decorate(directory, context); + + verify(context).saveMeasure(CoreMetrics.FUNCTION_COMPLEXITY, 2.5); + } + + @Test + public void noAverageIfMissingData() { + + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 20.0)); + Resource directory = new Directory("fake"); + + new AbstractFunctionComplexityDecorator(Java.INSTANCE) { + }.decorate(directory, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.FUNCTION_COMPLEXITY), anyDouble()); + } + + @Test + public void noAverageIfZeroFiles() { + AbstractFunctionComplexityDecorator decorator = new AbstractFunctionComplexityDecorator(Java.INSTANCE) { + }; + + Resource directory = new Directory("fake"); + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 0.0)); + when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 500.0)); + + decorator.decorate(directory, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.FUNCTION_COMPLEXITY), anyDouble()); + } + + @Test + public void doNotCalculateOnFiles() { + + Resource file = new File("fake"); + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 1.0)); + when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 25.0)); + + new AbstractFunctionComplexityDecorator(Java.INSTANCE) { + }.decorate(file, context); + + verify(context).saveMeasure(eq(CoreMetrics.FUNCTION_COMPLEXITY), anyDouble()); + } +} |