diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2018-05-30 10:45:00 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-06-01 20:20:47 +0200 |
commit | c72965048f5cf06bdf3414846a347402f2b8dddf (patch) | |
tree | 103f9f4142dd4f508a91d876906c00128bf53c8d /sonar-plugin-api/src/test/java/org/sonar | |
parent | a33103206a6787a4f85fb821cff8b5333f4babb3 (diff) | |
download | sonarqube-c72965048f5cf06bdf3414846a347402f2b8dddf.tar.gz sonarqube-c72965048f5cf06bdf3414846a347402f2b8dddf.zip |
SONAR-10809 Analyzers need to declare whether a rule is external
Diffstat (limited to 'sonar-plugin-api/src/test/java/org/sonar')
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java index 8398f50a2ae..0eefbb801ae 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java @@ -103,6 +103,7 @@ public class RulesDefinitionTest { RulesDefinition.Repository repo = context.repository("findbugs"); assertThat(repo.rules()).hasSize(2); + assertThat(repo.isExternal()).isFalse(); RulesDefinition.Rule rule = repo.rule("NPE"); assertThat(rule.scope()).isEqualTo(RuleScope.ALL); @@ -166,6 +167,51 @@ public class RulesDefinitionTest { } @Test + public void define_external_rules() { + RulesDefinition.NewRepository newRepo = context.createExternalRepository("eslint", "js"); + newRepo.createRule("NPE") + .setName("Detect NPE") + .setHtmlDescription("Detect <code>java.lang.NullPointerException</code>") + .setSeverity(Severity.BLOCKER) + .setInternalKey("/something") + .setStatus(RuleStatus.BETA) + .setTags("one", "two") + .setScope(RuleScope.ALL) + .addTags("two", "three", "four"); + + newRepo.createRule("ABC").setName("ABC").setMarkdownDescription("ABC"); + newRepo.done(); + + assertThat(context.repository("eslint")).isNull(); + RulesDefinition.Repository repo = context.repository("external_eslint"); + assertThat(repo.rules()).hasSize(2); + assertThat(repo.isExternal()).isTrue(); + + RulesDefinition.Rule rule = repo.rule("NPE"); + assertThat(rule.scope()).isEqualTo(RuleScope.ALL); + assertThat(rule.key()).isEqualTo("NPE"); + assertThat(rule.name()).isEqualTo("Detect NPE"); + assertThat(rule.severity()).isEqualTo(Severity.BLOCKER); + assertThat(rule.htmlDescription()).isEqualTo("Detect <code>java.lang.NullPointerException</code>"); + assertThat(rule.markdownDescription()).isNull(); + assertThat(rule.tags()).containsOnly("one", "two", "three", "four"); + assertThat(rule.params()).isEmpty(); + assertThat(rule.internalKey()).isEqualTo("/something"); + assertThat(rule.template()).isFalse(); + assertThat(rule.status()).isEqualTo(RuleStatus.BETA); + assertThat(rule.toString()).isEqualTo("[repository=external_eslint, key=NPE]"); + assertThat(rule.repository()).isSameAs(repo); + + RulesDefinition.Rule otherRule = repo.rule("ABC"); + assertThat(otherRule.htmlDescription()).isNull(); + assertThat(otherRule.markdownDescription()).isEqualTo("ABC"); + + // test equals() and hashCode() + assertThat(rule).isEqualTo(rule).isNotEqualTo(otherRule).isNotEqualTo("NPE").isNotEqualTo(null); + assertThat(rule.hashCode()).isEqualTo(rule.hashCode()); + } + + @Test public void define_rule_parameters() { RulesDefinition.NewRepository newFindbugs = context.createRepository("findbugs", "java"); RulesDefinition.NewRule newNpe = newFindbugs.createRule("NPE").setName("NPE").setHtmlDescription("NPE"); |