From 55825cb9babbbbbd685a2b7efbca0efc248de383 Mon Sep 17 00:00:00 2001 From: Amaury Levé Date: Wed, 27 Jun 2018 15:28:45 +0200 Subject: Update S4662: Rule should be parameterized (#92) --- .../test/java/org/sonar/css/plugin/RuleTest.java | 38 ---------------- .../org/sonar/css/plugin/rules/CssRuleTest.java | 53 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 38 deletions(-) delete mode 100644 sonar-css-plugin/src/test/java/org/sonar/css/plugin/RuleTest.java create mode 100644 sonar-css-plugin/src/test/java/org/sonar/css/plugin/rules/CssRuleTest.java (limited to 'sonar-css-plugin/src/test') diff --git a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/RuleTest.java b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/RuleTest.java deleted file mode 100644 index f842d4e..0000000 --- a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/RuleTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarCSS - * Copyright (C) 2018-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.css.plugin; - -import java.lang.reflect.InvocationTargetException; -import org.junit.Test; -import org.sonar.css.plugin.rules.CssRule; - -import static org.assertj.core.api.Assertions.assertThat; - -public class RuleTest { - - @Test - public void class_name_should_match_stylelint_key() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { - for (Class ruleClass : CssRules.getRuleClasses()) { - CssRule rule = (CssRule)ruleClass.getConstructor().newInstance(); - String stylelintRuleKeyWithoutUnderscore = rule.stylelintKey().replace("-", ""); - assertThat(ruleClass.getSimpleName()).isEqualToIgnoringCase(stylelintRuleKeyWithoutUnderscore); - } - } -} diff --git a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/rules/CssRuleTest.java b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/rules/CssRuleTest.java new file mode 100644 index 0000000..8b1e74c --- /dev/null +++ b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/rules/CssRuleTest.java @@ -0,0 +1,53 @@ +/* + * SonarCSS + * Copyright (C) 2018-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.css.plugin.rules; + +import com.google.gson.Gson; +import java.lang.reflect.InvocationTargetException; +import org.junit.Test; +import org.sonar.css.plugin.CssRules; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CssRuleTest { + + @Test + public void class_name_should_match_stylelint_key() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { + for (Class ruleClass : CssRules.getRuleClasses()) { + CssRule rule = (CssRule)ruleClass.getConstructor().newInstance(); + String stylelintRuleKeyWithoutUnderscore = rule.stylelintKey().replace("-", ""); + assertThat(ruleClass.getSimpleName()).isEqualToIgnoringCase(stylelintRuleKeyWithoutUnderscore); + } + } + + @Test + public void at_rule_unknown_default() { + String optionsAsJson = new Gson().toJson(new AtRuleNoUnknown().stylelintOptions()); + assertThat(optionsAsJson).isEqualTo("[true,{\"ignoreAtRules\":[\"content\",\"debug\",\"each\",\"else\",\"for\",\"function\",\"if\",\"include\",\"mixin\",\"return\",\"while\"]}]"); + } + + @Test + public void at_rule_unknown_custom() { + AtRuleNoUnknown instance = new AtRuleNoUnknown(); + instance.ignoredAtRules = "foo"; + String optionsAsJson = new Gson().toJson(instance.stylelintOptions()); + assertThat(optionsAsJson).isEqualTo("[true,{\"ignoreAtRules\":[\"foo\"]}]"); + } +} -- cgit v1.2.3