diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-11-29 17:00:54 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-11-29 17:00:54 +0000 |
commit | 6ce6cc598fdcd6e3d6eb662b47668b0c6b898f3d (patch) | |
tree | 0770d083d359e3e644ff64bf06dc8b9abc3ad04b /plugins/sonar-findbugs-plugin | |
parent | 0c4893c83a6873b224a50db86311082fd5af555f (diff) | |
download | sonarqube-6ce6cc598fdcd6e3d6eb662b47668b0c6b898f3d.tar.gz sonarqube-6ce6cc598fdcd6e3d6eb662b47668b0c6b898f3d.zip |
SONAR-249 improve core components to load rules and metrics
Diffstat (limited to 'plugins/sonar-findbugs-plugin')
-rw-r--r-- | plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FakeRuleFinder.java (renamed from plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsRuleFinder.java) | 16 | ||||
-rw-r--r-- | plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java | 23 | ||||
-rw-r--r-- | plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsSensorTest.java | 14 | ||||
-rw-r--r-- | plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java | 2 |
4 files changed, 29 insertions, 26 deletions
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsRuleFinder.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FakeRuleFinder.java index ab3af9d93a6..eae82300b29 100644 --- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsRuleFinder.java +++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FakeRuleFinder.java @@ -19,26 +19,30 @@ */ package org.sonar.plugins.findbugs; -import java.util.Collection; -import java.util.List; - import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RuleQuery; import org.sonar.api.rules.XMLRuleParser; -public class FindbugsRuleFinder implements RuleFinder { +import java.util.Collection; +import java.util.List; + +public class FakeRuleFinder implements RuleFinder { private final List<Rule> findbugsRules; - public FindbugsRuleFinder() { + public FakeRuleFinder() { FindbugsRuleRepository repo = new FindbugsRuleRepository(new XMLRuleParser()); findbugsRules = repo.createRules(); - for(Rule rule : findbugsRules){ + for (Rule rule : findbugsRules) { rule.setRepositoryKey(FindbugsConstants.REPOSITORY_KEY); } } + public Rule findById(int ruleId) { + throw new UnsupportedOperationException(); + } + public Rule findByKey(String repositoryKey, String key) { for (Rule rule : findbugsRules) { if (rule.getKey().equals(key)) { diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java index 9296f03613e..206ccdfc07d 100644 --- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java +++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java @@ -19,16 +19,7 @@ */ package org.sonar.plugins.findbugs; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringReader; -import java.util.List; - +import com.thoughtworks.xstream.XStream; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.sonar.api.profiles.RulesProfile; @@ -38,11 +29,19 @@ import org.sonar.plugins.findbugs.xml.FindBugsFilter; import org.sonar.plugins.findbugs.xml.Match; import org.sonar.test.TestUtils; -import com.thoughtworks.xstream.XStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.StringReader; +import java.util.List; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; public class FindbugsProfileImporterTest { - private FindbugsProfileImporter importer = new FindbugsProfileImporter(new FindbugsRuleFinder()); + private FindbugsProfileImporter importer = new FindbugsProfileImporter(new FakeRuleFinder()); @Test public void shouldImportPatterns() throws IOException { diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsSensorTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsSensorTest.java index d5124bf0f1a..9cd16af6c98 100644 --- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsSensorTest.java +++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsSensorTest.java @@ -48,14 +48,14 @@ public class FindbugsSensorTest extends FindbugsTests { @Test public void shouldExecuteWhenSomeRulesAreActive() throws Exception { - FindbugsSensor sensor = new FindbugsSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), null); + FindbugsSensor sensor = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), null); Project project = createProject(); assertTrue(sensor.shouldExecuteOnProject(project)); } @Test public void shouldExecuteWhenReuseExistingRulesConfig() throws Exception { - FindbugsSensor analyser = new FindbugsSensor(RulesProfile.create(), new FindbugsRuleFinder(), null); + FindbugsSensor analyser = new FindbugsSensor(RulesProfile.create(), new FakeRuleFinder(), null); Project pom = createProject(); when(pom.getReuseExistingRulesConfig()).thenReturn(true); assertTrue(analyser.shouldExecuteOnProject(pom)); @@ -63,7 +63,7 @@ public class FindbugsSensorTest extends FindbugsTests { @Test public void shouldNotExecuteWhenNoRulesAreActive() throws Exception { - FindbugsSensor analyser = new FindbugsSensor(RulesProfile.create(), new FindbugsRuleFinder(), null); + FindbugsSensor analyser = new FindbugsSensor(RulesProfile.create(), new FakeRuleFinder(), null); Project pom = createProject(); assertFalse(analyser.shouldExecuteOnProject(pom)); } @@ -72,7 +72,7 @@ public class FindbugsSensorTest extends FindbugsTests { public void shouldNotExecuteOnEar() { Project project = createProject(); when(project.getPom().getPackaging()).thenReturn("ear"); - FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), null); + FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), null); assertFalse(analyser.shouldExecuteOnProject(project)); } @@ -88,7 +88,7 @@ public class FindbugsSensorTest extends FindbugsTests { when(executor.execute()).thenReturn(xmlFile); when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass")); - FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), executor); + FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), executor); analyser.analyse(project, context); verify(executor).execute(); @@ -116,7 +116,7 @@ public class FindbugsSensorTest extends FindbugsTests { when(project.getConfiguration()).thenReturn(conf); when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass")); - FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), executor); + FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), executor); analyser.analyse(project, context); verify(executor, never()).execute(); @@ -144,7 +144,7 @@ public class FindbugsSensorTest extends FindbugsTests { when(project.getConfiguration()).thenReturn(conf); when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass")); - FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), executor); + FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), executor); analyser.analyse(project, context); verify(context, never()).saveViolation(any(Violation.class)); diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java index 881fbf9a36b..a21e3ccaecc 100644 --- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java +++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java @@ -31,7 +31,7 @@ public class SonarWayWithFindbugsProfileTest { @Test public void shouldCreateProfile() { - FindbugsProfileImporter importer = new FindbugsProfileImporter(new FindbugsRuleFinder()); + FindbugsProfileImporter importer = new FindbugsProfileImporter(new FakeRuleFinder()); SonarWayWithFindbugsProfile sonarWayWithFindbugs = new SonarWayWithFindbugsProfile(importer); ValidationMessages validation = ValidationMessages.create(); RulesProfile profile = sonarWayWithFindbugs.createProfile(validation); |