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/test | |
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/test')
2 files changed, 176 insertions, 0 deletions
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()); + } +} |