diff options
Diffstat (limited to 'sonar-deprecated')
10 files changed, 0 insertions, 492 deletions
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/AnnotatedCheck.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/AnnotatedCheck.java deleted file mode 100644 index da01fb10904..00000000000 --- a/sonar-deprecated/src/test/java/org/sonar/api/rules/AnnotatedCheck.java +++ /dev/null @@ -1,27 +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.rules; - -import org.sonar.check.Check; -import org.sonar.check.IsoCategory; - -@Check(title ="Annotated Check", description = "Description", isoCategory = IsoCategory.Reliability) -public class AnnotatedCheck { -} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/AnnotatedCheckWithParameters.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/AnnotatedCheckWithParameters.java deleted file mode 100644 index cd487c3d0a0..00000000000 --- a/sonar-deprecated/src/test/java/org/sonar/api/rules/AnnotatedCheckWithParameters.java +++ /dev/null @@ -1,44 +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.rules; - -import org.sonar.check.Check; -import org.sonar.check.CheckProperty; -import org.sonar.check.IsoCategory; - -@Check(key = "overriden_key",title ="Check with parameters", description = "Has parameters", isoCategory = IsoCategory.Efficiency) -public class AnnotatedCheckWithParameters { - - @CheckProperty(description ="Maximum value") - private String max; - - @CheckProperty(key = "overidden_min", description ="Minimum value") - protected String min; - - private int nonConfigurableProperty; - - public String getMax() { - return max; - } - - public void setMax(String max) { - this.max = max; - } -} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleAnnotationUtilsTest.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleAnnotationUtilsTest.java deleted file mode 100644 index 98d05bbd1f4..00000000000 --- a/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleAnnotationUtilsTest.java +++ /dev/null @@ -1,64 +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.rules; - -import org.hamcrest.core.Is; -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNot.not; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; - -public class RuleAnnotationUtilsTest { - - @Test - public void readAnnotatedClassWithoutParameters() { - Rule rule = RuleAnnotationUtils.readAnnotatedClass(AnnotatedCheck.class); - assertNotNull(rule); - assertThat(rule.getKey(), is(AnnotatedCheck.class.getName())); - assertThat(rule.getName(), is("Annotated Check")); - assertThat(rule.getConfigKey(), nullValue()); - assertThat(rule.getParams().size(), is(0)); - assertThat(rule.getDescription(), is("Description")); - assertThat(rule.getCardinality(), Is.is(Rule.Cardinality.SINGLE)); - assertThat(rule.getRulesCategory().getName(), Is.is(Iso9126RulesCategories.RELIABILITY.getName())); - } - - @Test - public void ruleKeyCanBeOverridden() { - Rule rule = RuleAnnotationUtils.readAnnotatedClass(AnnotatedCheckWithParameters.class); - assertNotNull(rule); - assertThat(rule.getKey(), is("overriden_key")); - } - @Test - public void readAnnotatedClassWithParameters() { - Rule rule = RuleAnnotationUtils.readAnnotatedClass(AnnotatedCheckWithParameters.class); - assertNotNull(rule); - assertThat(rule.getParams().size(), is(2)); - assertThat(rule.getParam("max"), not(nullValue())); - assertThat(rule.getParam("max").getDescription(), is("Maximum value")); - - assertThat(rule.getParam("min"), nullValue()); - assertThat(rule.getParam("overidden_min"), not(nullValue())); - assertThat(rule.getParam("overidden_min").getDescription(), is("Minimum value")); - } -} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/RulePriorityTest.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/RulePriorityTest.java deleted file mode 100644 index a3ed40321b8..00000000000 --- a/sonar-deprecated/src/test/java/org/sonar/api/rules/RulePriorityTest.java +++ /dev/null @@ -1,44 +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.rules; - -import static junit.framework.Assert.assertEquals; - -import junit.framework.Assert; -import org.junit.Test; - -public class RulePriorityTest { - - @Test - public void testValueOfString() { - Assert.assertEquals(RulePriority.INFO, RulePriority.valueOfString("info")); - Assert.assertEquals(RulePriority.MAJOR, RulePriority.valueOfString("MAJOR")); - Assert.assertEquals(RulePriority.MAJOR, RulePriority.valueOfString("ERROR")); - Assert.assertEquals(RulePriority.INFO, RulePriority.valueOfString("WARNING")); - Assert.assertEquals(RulePriority.MAJOR, RulePriority.valueOfString("ErRor")); - Assert.assertEquals(RulePriority.INFO, RulePriority.valueOfString("WaRnInG")); - } - - @Test(expected = IllegalArgumentException.class) - public void testUnknownValueOfString() { - RulePriority.valueOfString("make me crash"); - } - -} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleTest.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleTest.java deleted file mode 100644 index c0767fda0ad..00000000000 --- a/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleTest.java +++ /dev/null @@ -1,95 +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.rules; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; - -import org.hamcrest.core.Is; -import org.junit.Assert; -import org.junit.Test; - -import java.util.Arrays; -import java.util.List; - -public class RuleTest { - - @Test - public void descriptionShouldBeCleaned() { - Rule rule = new Rule(); - rule.setDescription(" my description "); - Assert.assertEquals("my description", rule.getDescription()); - - rule.setDescription(null); - assertNull(rule.getDescription()); - } - - @Test - public void shouldRemoveNewLineCharactersInNameWithSetter() { - Rule rule = new Rule(); - for (String example : getExamplesContainingNewLineCharacter()) { - rule.setName(example); - assertThat(rule.getName(), is("test")); - } - } - - @Test - public void shouldRemoveNewLineCharactersInNameWithfirstConstructor() { - Rule rule; - for (String example : getExamplesContainingNewLineCharacter()) { - rule = new Rule(null, null, example, (RulesCategory) null, null); - assertThat(rule.getName(), is("test")); - } - } - - @Test - public void shouldRemoveNewLineCharactersInNameWithSecondConstructor() { - Rule rule; - for (String example : getExamplesContainingNewLineCharacter()) { - rule = new Rule(null, null, example, (RulesCategory)null, null); - assertThat(rule.getName(), is("test")); - } - } - - @Test - public void defaultPriorityIsMajor() { - Rule rule = new Rule(); - assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR)); - - rule = new Rule("name", "key"); - assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR)); - - rule = new Rule("pkey", "key", "name", Iso9126RulesCategories.EFFICIENCY, null, null); - assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR)); - - rule.setPriority(RulePriority.BLOCKER); - assertThat(rule.getPriority(), Is.is(RulePriority.BLOCKER)); - - rule.setPriority(null); - assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR)); - } - - - private List<String> getExamplesContainingNewLineCharacter() { - return Arrays.asList("te\nst", "te\ns\nt", "te\rst", "te\n\rst", "te\r\nst"); - } - - -} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleUtilsTest.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleUtilsTest.java deleted file mode 100644 index c60a5fdf604..00000000000 --- a/sonar-deprecated/src/test/java/org/sonar/api/rules/RuleUtilsTest.java +++ /dev/null @@ -1,66 +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.rules; - -import org.apache.commons.configuration.Configuration; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import org.junit.Test; -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 org.mockito.Matchers; -import org.sonar.api.CoreProperties; - -import java.util.Map; - -public class RuleUtilsTest { - - @Test - public void getPriorityWeights() { - Configuration conf = mock(Configuration.class); - when(conf.getString(Matchers.eq(CoreProperties.CORE_RULE_WEIGHTS_PROPERTY), anyString())).thenReturn("info=0;minor=1;major=2;critical=5;blocker=10"); - - final Map<RulePriority, Integer> map = RuleUtils.getPriorityWeights(conf); - - assertThat(map.get(RulePriority.BLOCKER), is(10)); - assertThat(map.get(RulePriority.CRITICAL), is(5)); - assertThat(map.get(RulePriority.MAJOR), is(2)); - assertThat(map.get(RulePriority.MINOR), is(1)); - assertThat(map.get(RulePriority.INFO), is(0)); - } - - @Test - public void loadMissingWeights() { - Configuration conf = mock(Configuration.class); - when(conf.getString(Matchers.eq(CoreProperties.CORE_RULE_WEIGHTS_PROPERTY), anyString())).thenReturn("foo=0;bar=1;CRITICAL=5"); - - final Map<RulePriority, Integer> map = RuleUtils.getPriorityWeights(conf); - - assertThat(map.get(RulePriority.BLOCKER), is(1)); - assertThat(map.get(RulePriority.CRITICAL), is(5)); - assertThat(map.get(RulePriority.MAJOR), is(1)); - assertThat(map.get(RulePriority.MINOR), is(1)); - assertThat(map.get(RulePriority.INFO), is(1)); - } - -} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRuleXmlFormatTest.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRuleXmlFormatTest.java deleted file mode 100644 index a1cfb59336c..00000000000 --- a/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRuleXmlFormatTest.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.rules; - -import org.hamcrest.core.Is; -import org.junit.Test; -import org.sonar.api.utils.SonarException; - -import java.io.StringReader; -import java.util.List; - -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNot.not; -import static org.hamcrest.core.IsNull.nullValue; -import static org.junit.Assert.assertThat; - -public class StandardRuleXmlFormatTest { - - @Test - public void parseXml() { - List<Rule> rules = StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/api/rules/StandardRuleXmlFormatTest/rules.xml")); - assertThat(rules.size(), is(2)); - - Rule rule = rules.get(0); - assertThat(rule.getName(), is("Local Variable Name")); - assertThat(rule.getDescription(), is("Checks that local, non-final variable names conform to a format specified by the format property.")); - assertThat(rule.getPriority(), Is.is(RulePriority.BLOCKER)); - assertThat(rule.getCardinality(), Is.is(Rule.Cardinality.MULTIPLE)); - assertThat(rule.getConfigKey(), is("Checker/TreeWalker/LocalVariableName")); - - assertThat(rule.getParams().size(), is(2)); - RuleParam prop = rule.getParam("ignore"); - assertThat(prop.getKey(), is("ignore")); - assertThat(prop.getDescription(), is("Ignore ?")); - - Rule minimalRule = rules.get(1); - assertThat(minimalRule.getKey(), is("com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck")); - assertThat(minimalRule.getParams().size(), is(0)); - - } - - @Test(expected = SonarException.class) - public void failIfMissingRuleKey() { - StandardRuleXmlFormat.parseXml(new StringReader("<rules><rule><name>Foo</name></rule></rules>")); - } - - @Test(expected = SonarException.class) - public void failIfMissingPropertyKey() { - StandardRuleXmlFormat.parseXml(new StringReader("<rules><rule><key>foo</key><name>Foo</name><param></param></rule></rules>")); - } - - @Test - public void utf8Encoding() { - List<Rule> rules = StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/api/rules/StandardRuleXmlFormatTest/utf8.xml")); - assertThat(rules.size(), is(1)); - Rule rule = rules.get(0); - assertThat(rule.getKey(), is("com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck")); - assertThat(rule.getName(), is("M & M")); - assertThat(rule.getDescription().charAt(0), is('\u00E9')); - assertThat(rule.getDescription().charAt(1), is('\u00E0')); - assertThat(rule.getDescription().charAt(2), is('\u0026')); - } - - @Test - public void supportDeprecatedFormat() { - // the deprecated format uses some attributes instead of nodes - List<Rule> rules = StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml")); - assertThat(rules.size(), is(1)); - Rule rule = rules.get(0); - assertThat(rule.getPriority(), Is.is(RulePriority.CRITICAL)); - assertThat(rule.getKey(), is("org.sonar.it.checkstyle.MethodsCountCheck")); - assertThat(rule.getParam("minMethodsCount"), not(nullValue())); - } -} diff --git a/sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml b/sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml deleted file mode 100644 index 44cf56d228a..00000000000 --- a/sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml +++ /dev/null @@ -1,11 +0,0 @@ -<rules> - <rule key="org.sonar.it.checkstyle.MethodsCountCheck" priority="CRITICAL"> - <name>Methods Count Check</name> - <configKey>Checker/TreeWalker/org.sonar.it.checkstyle.MethodsCountCheck</configKey> - <category name="Usability"/> - <description>Count methods.</description> - <param key="minMethodsCount" type="i"> - <description>Le nombre minimum de méthodes. 10 par défaut.</description> - </param> - </rule> -</rules>
\ No newline at end of file diff --git a/sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/rules.xml b/sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/rules.xml deleted file mode 100644 index c4038bdf96c..00000000000 --- a/sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/rules.xml +++ /dev/null @@ -1,39 +0,0 @@ -<rules> - <rule> - <!-- with exhaustive fields --> - <key>com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck</key> - <name>Local Variable Name</name> - <description> - <![CDATA[Checks that local, non-final variable names conform to a format specified by the format property.]]> - </description> - <isoCategory>Efficiency</isoCategory> - <configKey>Checker/TreeWalker/LocalVariableName</configKey> - <priority>BLOCKER</priority> - <cardinality>MULTIPLE</cardinality> - <param> - <key>tokens</key> - <description> - <![CDATA[ - Controls whether the check applies to variable declarations or catch clause parameters - ]]> - </description> - </param> - <param> - <key>ignore</key> - <description> - Ignore ? - </description> - </param> - </rule> - - - <rule> - <!-- with only required fields --> - <key>com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck</key> - <name>Magic Number</name> - <description> - <![CDATA[Checks for magic numbers.]]> - </description> - <isoCategory>Maintainability</isoCategory> - </rule> -</rules>
\ No newline at end of file diff --git a/sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/utf8.xml b/sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/utf8.xml deleted file mode 100644 index 6197e030057..00000000000 --- a/sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/utf8.xml +++ /dev/null @@ -1,11 +0,0 @@ -<rules> - <rule> - <key>com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck</key> - <priority>BLOCKER</priority> - <configKey>Checker/TreeWalker/LocalVariableName</configKey> - <name>M & M</name> - <description> - <![CDATA[éà&]]> - </description> - </rule> -</rules> |