From 32f6d46600091ea351b1657eb6233f8648ec69cc Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 8 Apr 2014 17:46:45 +0200 Subject: SONAR-5195 Rule templates should not define technical debt informations --- .../org/sonar/api/server/rule/RulesDefinition.java | 3 +++ .../sonar/api/server/rule/RulesDefinitionTest.java | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'sonar-plugin-api/src') diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java index 831a05f1155..ba5870588ca 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java @@ -687,6 +687,9 @@ public interface RulesDefinition extends ServerExtension { if ((Strings.isNullOrEmpty(debtSubCharacteristic) && debtRemediationFunction != null) || (!Strings.isNullOrEmpty(debtSubCharacteristic) && debtRemediationFunction == null)) { throw new IllegalStateException(String.format("Both debt sub-characteristic and debt remediation function should be defined on rule '%s'", this)); } + if (!Strings.isNullOrEmpty(debtSubCharacteristic) && template) { + throw new IllegalStateException(String.format("'%s' is a rule template, it should not define technical debt.", this)); + } } @Override 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 1027e8ba3fc..43a88eaffe0 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 @@ -340,4 +340,26 @@ public class RulesDefinitionTest { } } + /** + * SONAR-5195 + */ + @Test + public void fail_if_rule_template_define_technical_debt() { + RulesDefinition.NewRepository newRepo = context.createRepository("squid", "java"); + RulesDefinition.NewRule newRule = newRepo.createRule("XPath rule") + .setTemplate(true) + .setName("Insufficient branch coverage") + .setHtmlDescription("This rule allows to define some homemade Java rules with help of an XPath expression.") + .setSeverity(Severity.MAJOR) + .setDebtSubCharacteristic(RulesDefinition.SubCharacteristics.UNIT_TESTS); + newRule.setDebtRemediationFunction(newRule.debtRemediationFunctions().linearWithOffset("1h", "10min")); + + try { + newRepo.done(); + fail(); + } catch (IllegalStateException e) { + assertThat(e).hasMessage("'[repository=squid, key=XPath rule]' is a rule template, it should not define technical debt."); + } + } + } -- cgit v1.2.3