aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test/java
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-01-28 13:17:57 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-01-28 13:18:46 +0100
commitb8eecc041ad4aa23a3bf5cf7c8847573b125d187 (patch)
treed0b719f881f8f324d574fa699bd6befb7608c058 /sonar-plugin-api/src/test/java
parent220dd330306d76b7ff13baa07abf461688c92fc1 (diff)
downloadsonarqube-b8eecc041ad4aa23a3bf5cf7c8847573b125d187.tar.gz
sonarqube-b8eecc041ad4aa23a3bf5cf7c8847573b125d187.zip
SONAR-2149 Resource filters are ignored in complexity distributions of Java projects
This issue implies SONAR-2153 : API: A decorator should override formulas
Diffstat (limited to 'sonar-plugin-api/src/test/java')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/FormulaDecoratorTest.java91
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java2
2 files changed, 2 insertions, 91 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/FormulaDecoratorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/FormulaDecoratorTest.java
deleted file mode 100644
index 50865b26ae0..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/FormulaDecoratorTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.batch;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import org.junit.Test;
-import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.*;
-import org.sonar.api.measures.*;
-import org.sonar.api.test.IsMeasure;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-public class FormulaDecoratorTest {
-
- @Test
- public void doAlwaysExecute() {
- assertThat(new FormulaDecorator(CoreMetrics.LINES).shouldExecuteOnProject(null), is(true));
- }
-
- @Test
- public void declareDependencies() {
- Formula formula = new Formula() {
- public List<Metric> dependsUponMetrics() {
- return Arrays.asList(CoreMetrics.COMPLEXITY, CoreMetrics.COVERAGE);
- }
-
- public Measure calculate(FormulaData data, FormulaContext context) {
- return null;
- }
- };
- Metric metric = new Metric().setFormula(formula);
- List<Metric> dependencies = new FormulaDecorator(metric).dependsUponMetrics();
- assertThat(dependencies, hasItem(CoreMetrics.COMPLEXITY));
- assertThat(dependencies, hasItem(CoreMetrics.COVERAGE));
- }
-
- @Test
- public void saveMeasure() {
- FormulaDecorator decorator = new FormulaDecorator(new Metric("fake").setFormula(new FakeFormula()));
-
- DecoratorContext context = mock(DecoratorContext.class);
- decorator.decorate(null, context);
-
- verify(context).saveMeasure(argThat(new IsMeasure(new Metric("fake"), 50.0)));
- }
-
- @Test
- public void doNotExecuteIfExistingResult() {
- Metric fake = new Metric("fake");
- FormulaDecorator decorator = new FormulaDecorator(fake.setFormula(new FakeFormula()));
-
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(fake)).thenReturn(new Measure(fake, 10.0));
- decorator.decorate(null, context);
-
- verify(context, never()).saveMeasure((Measure) anyObject());
- }
-
- class FakeFormula implements Formula {
-
- public List<Metric> dependsUponMetrics() {
- return Collections.emptyList();
- }
-
- public Measure calculate(FormulaData data, FormulaContext context) {
- return new Measure(new Metric("fake")).setValue(50.0);
- }
- }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java
index 9849c28d035..93d89b98abb 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java
@@ -22,6 +22,7 @@ package org.sonar.api.measures;
import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
+import org.sonar.api.resources.File;
import java.util.Collections;
import java.util.List;
@@ -42,6 +43,7 @@ public class SumChildDistributionFormulaTest {
public void init() {
formula = new SumChildDistributionFormula();
context = mock(FormulaContext.class);
+ when(context.getResource()).thenReturn(new File("foo"));
data = mock(FormulaData.class);
}