aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-03-25 10:24:16 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-03-25 12:45:16 +0100
commit74abc65d43b9f5af2fd67a8c316c36afec4bed8d (patch)
treed378ed4ebdee816272ea0f46510afa2ab06c0c53 /plugins
parent9e4f4088f57a688e7865604ac3eef7153fc19eec (diff)
downloadsonarqube-74abc65d43b9f5af2fd67a8c316c36afec4bed8d.tar.gz
sonarqube-74abc65d43b9f5af2fd67a8c316c36afec4bed8d.zip
SONAR-5154 A plugin should fail when using classes JavaFile or JavaPackage
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java33
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java4
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java30
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java39
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java11
5 files changed, 63 insertions, 54 deletions
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java
index 5078959dfe9..adb52dfece0 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java
@@ -23,14 +23,20 @@ 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.resources.*;
+import org.sonar.api.resources.Directory;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Resource;
import java.util.Arrays;
import java.util.Collections;
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class DirectoriesDecoratorTest {
@@ -61,33 +67,24 @@ public class DirectoriesDecoratorTest {
DecoratorContext context = mock(DecoratorContext.class);
when(context.getChildrenMeasures(CoreMetrics.DIRECTORIES)).thenReturn(Arrays.<Measure>asList(
- new Measure(CoreMetrics.DIRECTORIES, 1.0),
- new Measure(CoreMetrics.DIRECTORIES, 1.0),
- new Measure(CoreMetrics.DIRECTORIES, 1.0)
- ));
+ new Measure(CoreMetrics.DIRECTORIES, 1.0),
+ new Measure(CoreMetrics.DIRECTORIES, 1.0),
+ new Measure(CoreMetrics.DIRECTORIES, 1.0)
+ ));
decorator.decorate(project, context);
verify(context).saveMeasure(CoreMetrics.DIRECTORIES, 3.0);
}
@Test
- public void packagesAreConsideredAsDirectories() {
- DirectoriesDecorator decorator = new DirectoriesDecorator();
- Resource pac = new JavaPackage("org/foo");
- DecoratorContext context = mock(DecoratorContext.class);
- decorator.decorate(pac, context);
- verify(context).saveMeasure(eq(CoreMetrics.DIRECTORIES), eq(1.0));
- }
-
- @Test
public void noProjectValueWhenOnlyPackages() {
DirectoriesDecorator decorator = new DirectoriesDecorator();
Resource project = new Project("project");
DecoratorContext context = mock(DecoratorContext.class);
when(context.getChildrenMeasures(CoreMetrics.DIRECTORIES)).thenReturn(Collections.<Measure>emptyList());
when(context.getChildrenMeasures(CoreMetrics.PACKAGES)).thenReturn(Arrays.<Measure>asList(
- new Measure(CoreMetrics.PACKAGES, 1.0),
- new Measure(CoreMetrics.PACKAGES, 1.0)
- ));
+ new Measure(CoreMetrics.PACKAGES, 1.0),
+ new Measure(CoreMetrics.PACKAGES, 1.0)
+ ));
decorator.decorate(project, context);
verify(context, never()).saveMeasure(eq(CoreMetrics.DIRECTORIES), anyDouble());
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java
index ed824032359..2731680adc9 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java
@@ -22,7 +22,7 @@ package org.sonar.plugins.core.sensors;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.File;
import org.sonar.api.test.IsMeasure;
import org.sonar.core.metric.DefaultMetricFinder;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@@ -39,7 +39,7 @@ public class ManualMeasureDecoratorTest extends AbstractDbUnitTestCase {
public void testCopyManualMeasures() throws Exception {
setupData("testCopyManualMeasures");
- JavaFile javaFile = new JavaFile("Foo.java");
+ File javaFile = new File("Foo.java");
javaFile.setId(40);
ManualMeasureDecorator decorator = new ManualMeasureDecorator(getSession(), new DefaultMetricFinder(getSessionFactory()));
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
index 55c8316da8b..8713c66537b 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
@@ -26,7 +26,7 @@ import org.sonar.api.batch.TimeMachineQuery;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MetricFinder;
-import org.sonar.api.resources.JavaPackage;
+import org.sonar.api.resources.Directory;
import org.sonar.api.resources.Project;
import java.text.ParseException;
@@ -37,7 +37,11 @@ import java.util.Date;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItems;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.anyList;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class TendencyDecoratorTest {
@@ -65,19 +69,19 @@ public class TendencyDecoratorTest {
TimeMachine timeMachine = mock(TimeMachine.class);
when(timeMachine.getMeasuresFields(query)).thenReturn(Arrays.<Object[]>asList(
- new Object[]{date("2009-12-01"), CoreMetrics.LINES, 1200.0},
- new Object[]{date("2009-12-01"), CoreMetrics.COVERAGE, 80.5},
- new Object[]{date("2009-12-02"), CoreMetrics.LINES, 1300.0},
- new Object[]{date("2009-12-02"), CoreMetrics.COVERAGE, 79.6},
- new Object[]{date("2009-12-15"), CoreMetrics.LINES, 1150.0}
- ));
+ new Object[] {date("2009-12-01"), CoreMetrics.LINES, 1200.0},
+ new Object[] {date("2009-12-01"), CoreMetrics.COVERAGE, 80.5},
+ new Object[] {date("2009-12-02"), CoreMetrics.LINES, 1300.0},
+ new Object[] {date("2009-12-02"), CoreMetrics.COVERAGE, 79.6},
+ new Object[] {date("2009-12-15"), CoreMetrics.LINES, 1150.0}
+ ));
DecoratorContext context = mock(DecoratorContext.class);
when(context.getMeasure(CoreMetrics.LINES)).thenReturn(new Measure(CoreMetrics.LINES, 1400.0));
when(context.getMeasure(CoreMetrics.COVERAGE)).thenReturn(new Measure(CoreMetrics.LINES, 90.0));
TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
- decorator.decorate(new JavaPackage("org.foo"), context);
+ decorator.decorate(new Directory("org/foo"), context);
verify(analyser).analyseLevel(Arrays.asList(1200.0, 1300.0, 1150.0, 1400.0));
verify(analyser).analyseLevel(Arrays.asList(80.5, 79.6, 90.0));
@@ -90,13 +94,13 @@ public class TendencyDecoratorTest {
TimeMachine timeMachine = mock(TimeMachine.class);
when(timeMachine.getMeasuresFields(query)).thenReturn(Arrays.<Object[]>asList(
- new Object[]{date("2009-12-01"), CoreMetrics.LINES, 1200.0},
- new Object[]{date("2009-12-02"), CoreMetrics.LINES, 1300.0}
- ));
+ new Object[] {date("2009-12-01"), CoreMetrics.LINES, 1200.0},
+ new Object[] {date("2009-12-02"), CoreMetrics.LINES, 1300.0}
+ ));
DecoratorContext context = mock(DecoratorContext.class);
TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
- decorator.decorate(new JavaPackage("org.foo"), context);
+ decorator.decorate(new Directory("org/foo"), context);
verify(analyser, never()).analyseLevel(anyList());
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
index bd502b99ede..fe48596751c 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
@@ -22,9 +22,13 @@ package org.sonar.plugins.core.timemachine;
import org.junit.Test;
import org.mockito.Matchers;
import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.measures.*;
+import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.MeasuresFilter;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.measures.MetricFinder;
+import org.sonar.api.measures.RuleMeasure;
+import org.sonar.api.resources.Directory;
import org.sonar.api.resources.File;
-import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Rule;
@@ -37,7 +41,10 @@ import java.util.Arrays;
import java.util.Date;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class VariationDecoratorTest extends AbstractDbUnitTestCase {
@@ -61,20 +68,20 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
@Test
public void shouldCompareAndSaveVariation() {
- Resource javaPackage = new JavaPackage("org.foo");
+ Resource dir = new Directory("org/foo");
PastMeasuresLoader pastMeasuresLoader = mock(PastMeasuresLoader.class);
PastSnapshot pastSnapshot1 = new PastSnapshot("days", new Date()).setIndex(1);
PastSnapshot pastSnapshot3 = new PastSnapshot("days", new Date()).setIndex(3);
// first past analysis
- when(pastMeasuresLoader.getPastMeasures(javaPackage, pastSnapshot1)).thenReturn(Arrays.asList(
- new Object[]{NCLOC_ID, null, null, null, 180.0},
- new Object[]{COVERAGE_ID, null, null, null, 75.0}));
+ when(pastMeasuresLoader.getPastMeasures(dir, pastSnapshot1)).thenReturn(Arrays.asList(
+ new Object[] {NCLOC_ID, null, null, null, 180.0},
+ new Object[] {COVERAGE_ID, null, null, null, 75.0}));
// second past analysis
- when(pastMeasuresLoader.getPastMeasures(javaPackage, pastSnapshot3)).thenReturn(Arrays.<Object[]>asList(
- new Object[]{NCLOC_ID, null, null, null, 240.0}));
+ when(pastMeasuresLoader.getPastMeasures(dir, pastSnapshot3)).thenReturn(Arrays.<Object[]>asList(
+ new Object[] {NCLOC_ID, null, null, null, 240.0}));
// current analysis
DecoratorContext context = mock(DecoratorContext.class);
@@ -83,7 +90,7 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
when(context.getMeasures(Matchers.<MeasuresFilter>anyObject())).thenReturn(Arrays.asList(currentNcloc, currentCoverage));
VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1, pastSnapshot3));
- decorator.decorate(javaPackage, context);
+ decorator.decorate(dir, context);
// context updated for each variation : 2 times for ncloc and 1 time for coverage
verify(context, times(3)).saveMeasure(Matchers.<Measure>anyObject());
@@ -104,16 +111,16 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
Rule rule2 = Rule.create();
rule2.setId(2);
- Resource javaPackage = new JavaPackage("org.foo");
+ Resource dir = new Directory("org/foo");
PastMeasuresLoader pastMeasuresLoader = mock(PastMeasuresLoader.class);
PastSnapshot pastSnapshot1 = new PastSnapshot("days", new Date()).setIndex(1);
// first past analysis
- when(pastMeasuresLoader.getPastMeasures(javaPackage, pastSnapshot1)).thenReturn(Arrays.asList(
- new Object[]{VIOLATIONS_ID, null, null, null, 180.0},// total
- new Object[]{VIOLATIONS_ID, null, null, rule1.getId(), 100.0},// rule 1
- new Object[]{VIOLATIONS_ID, null, null, rule2.getId(), 80.0})); // rule 2
+ when(pastMeasuresLoader.getPastMeasures(dir, pastSnapshot1)).thenReturn(Arrays.asList(
+ new Object[] {VIOLATIONS_ID, null, null, null, 180.0},// total
+ new Object[] {VIOLATIONS_ID, null, null, rule1.getId(), 100.0},// rule 1
+ new Object[] {VIOLATIONS_ID, null, null, rule2.getId(), 80.0})); // rule 2
// current analysis
DecoratorContext context = mock(DecoratorContext.class);
@@ -123,7 +130,7 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
when(context.getMeasures(Matchers.<MeasuresFilter>anyObject())).thenReturn(Arrays.asList(violations, violationsRule1, violationsRule2));
VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1));
- decorator.decorate(javaPackage, context);
+ decorator.decorate(dir, context);
// context updated for each variation
verify(context, times(3)).saveMeasure(Matchers.<Measure>anyObject());
diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java
index c1af92310c4..7ebae1da257 100644
--- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java
+++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java
@@ -23,8 +23,8 @@ 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.resources.JavaFile;
-import org.sonar.api.resources.Resource;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.test.IsMeasure;
import static org.hamcrest.CoreMatchers.is;
@@ -48,7 +48,8 @@ public class SumDuplicationsDecoratorTest {
@Test
public void doNotSetDuplicationsOnUnitTests() {
SumDuplicationsDecorator decorator = new SumDuplicationsDecorator();
- Resource unitTest = new JavaFile("org.foo.BarTest", true);
+ File unitTest = new File("org/foo/BarTest.java");
+ unitTest.setQualifier(Qualifiers.UNIT_TEST_FILE);
DecoratorContext context = mock(DecoratorContext.class);
decorator.decorate(unitTest, context);
@@ -59,10 +60,10 @@ public class SumDuplicationsDecoratorTest {
@Test
public void saveZeroIfNoDuplications() {
SumDuplicationsDecorator decorator = new SumDuplicationsDecorator();
- Resource unitTest = new JavaFile("org.foo.BarTest", false);
+ File file = new File("org/foo/BarTest.java");
DecoratorContext context = mock(DecoratorContext.class);
- decorator.decorate(unitTest, context);
+ decorator.decorate(file, context);
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.DUPLICATED_LINES, 0.0)));
}