-/*\r
- * Sonar, open source software quality management tool.\r
- * Copyright (C) 2009 SonarSource SA\r
- * mailto:contact AT sonarsource DOT com\r
- *\r
- * Sonar is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Lesser General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 3 of the License, or (at your option) any later version.\r
- *\r
- * Sonar is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Lesser General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with Sonar; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02\r
- */\r
-package org.sonar.plugins.findbugs;\r
-\r
-import org.mockito.invocation.InvocationOnMock;\r
-import org.mockito.stubbing.Answer;\r
-import org.sonar.api.CoreProperties;\r
-import org.sonar.api.profiles.RulesProfile;\r
-import org.sonar.api.resources.Java;\r
-import org.sonar.api.rules.*;\r
-import org.sonar.test.TestUtils;\r
-import org.xml.sax.SAXException;\r
-\r
-import java.io.IOException;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import static org.mockito.Matchers.anyString;\r
-import static org.mockito.Matchers.eq;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.when;\r
-\r
-public abstract class FindbugsTests {\r
-\r
- protected void assertXmlAreSimilar(String actualContent, String expectedFileName) throws IOException, SAXException {\r
- String expectedContent = TestUtils.getResourceContent("/org/sonar/plugins/findbugs/" + expectedFileName);\r
- TestUtils.assertSimilarXml(expectedContent, actualContent);\r
- }\r
-\r
- protected List<Rule> buildRulesFixture() {\r
- List<Rule> rules = new ArrayList<Rule>();\r
-\r
- Rule rule1 = Rule.create(FindbugsConstants.REPOSITORY_KEY, "DLS_DEAD_LOCAL_STORE", "DLS: Dead store to local variable");\r
- Rule rule2 = Rule.create(FindbugsConstants.REPOSITORY_KEY, "URF_UNREAD_FIELD", "UrF: Unread field");\r
-\r
- rules.add(rule1);\r
- rules.add(rule2);\r
-\r
- return rules;\r
- }\r
-\r
- protected List<ActiveRule> buildActiveRulesFixture(List<Rule> rules) {\r
- List<ActiveRule> activeRules = new ArrayList<ActiveRule>();\r
- ActiveRule activeRule1 = new ActiveRule(null, rules.get(0), RulePriority.CRITICAL);\r
- activeRules.add(activeRule1);\r
- ActiveRule activeRule2 = new ActiveRule(null, rules.get(1), RulePriority.MAJOR);\r
- activeRules.add(activeRule2);\r
- return activeRules;\r
- }\r
-\r
- protected RulesManager createRulesManager() {\r
- RulesManager rulesManager = mock(RulesManager.class);\r
-\r
- when(rulesManager.getPluginRule(eq(CoreProperties.FINDBUGS_PLUGIN), anyString())).thenAnswer(new Answer<Rule>() {\r
-\r
- public Rule answer(InvocationOnMock invocationOnMock) throws Throwable {\r
- Object[] args = invocationOnMock.getArguments();\r
- Rule rule = Rule.create();\r
- rule.setPluginName((String) args[0]);\r
- rule.setKey((String) args[1]);\r
- return rule;\r
- }\r
- });\r
- return rulesManager;\r
- }\r
-\r
- protected RulesProfile createRulesProfileWithActiveRules() {\r
- RulesProfile profile = RulesProfile.create();\r
- profile.setName(RulesProfile.SONAR_WAY_FINDBUGS_NAME);\r
- profile.setLanguage(Java.KEY);\r
- for (Rule rule : new FindbugsRuleRepository(new XMLRuleParser()).createRules()) {\r
- rule.setRepositoryKey(FindbugsConstants.REPOSITORY_KEY);\r
- profile.activateRule(rule, null);\r
- }\r
- return profile;\r
- }\r
-}\r
+/*
+ * 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.plugins.findbugs;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.platform.ServerFileSystem;
+import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.resources.Java;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RulePriority;
+import org.sonar.api.rules.RulesManager;
+import org.sonar.api.rules.XMLRuleParser;
+import org.sonar.test.TestUtils;
+import org.xml.sax.SAXException;
+
+public abstract class FindbugsTests {
+
+ protected void assertXmlAreSimilar(String actualContent, String expectedFileName) throws IOException, SAXException {
+ String expectedContent = TestUtils.getResourceContent("/org/sonar/plugins/findbugs/" + expectedFileName);
+ TestUtils.assertSimilarXml(expectedContent, actualContent);
+ }
+
+ protected List<Rule> buildRulesFixture() {
+ List<Rule> rules = new ArrayList<Rule>();
+
+ Rule rule1 = Rule.create(FindbugsConstants.REPOSITORY_KEY, "DLS_DEAD_LOCAL_STORE", "DLS: Dead store to local variable");
+ Rule rule2 = Rule.create(FindbugsConstants.REPOSITORY_KEY, "URF_UNREAD_FIELD", "UrF: Unread field");
+
+ rules.add(rule1);
+ rules.add(rule2);
+
+ return rules;
+ }
+
+ protected List<ActiveRule> buildActiveRulesFixture(List<Rule> rules) {
+ List<ActiveRule> activeRules = new ArrayList<ActiveRule>();
+ ActiveRule activeRule1 = new ActiveRule(null, rules.get(0), RulePriority.CRITICAL);
+ activeRules.add(activeRule1);
+ ActiveRule activeRule2 = new ActiveRule(null, rules.get(1), RulePriority.MAJOR);
+ activeRules.add(activeRule2);
+ return activeRules;
+ }
+
+ protected RulesManager createRulesManager() {
+ RulesManager rulesManager = mock(RulesManager.class);
+
+ when(rulesManager.getPluginRule(eq(CoreProperties.FINDBUGS_PLUGIN), anyString())).thenAnswer(new Answer<Rule>() {
+
+ public Rule answer(InvocationOnMock invocationOnMock) throws Throwable {
+ Object[] args = invocationOnMock.getArguments();
+ Rule rule = Rule.create();
+ rule.setPluginName((String) args[0]);
+ rule.setKey((String) args[1]);
+ return rule;
+ }
+ });
+ return rulesManager;
+ }
+
+ protected RulesProfile createRulesProfileWithActiveRules() {
+ RulesProfile profile = RulesProfile.create();
+ profile.setName(RulesProfile.SONAR_WAY_FINDBUGS_NAME);
+ profile.setLanguage(Java.KEY);
+ ServerFileSystem sfs = mock(ServerFileSystem.class);
+ for (Rule rule : new FindbugsRuleRepository(sfs, new XMLRuleParser()).createRules()) {
+ rule.setRepositoryKey(FindbugsConstants.REPOSITORY_KEY);
+ profile.activateRule(rule, null);
+ }
+ return profile;
+ }
+}