From 79ebf35daa3acad4ec270ab193e1506d57f9afed Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 4 Apr 2014 11:47:15 +0200 Subject: [PATCH] Create a specific unit test of declaring rules with technical debt --- .../api/server/rule/RulesDefinitionTest.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 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 3a028382d3c..1027e8ba3fc 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 @@ -65,17 +65,14 @@ public class RulesDefinitionTest { @Test public void define_rules() { RulesDefinition.NewRepository newRepo = context.createRepository("findbugs", "java"); - RulesDefinition.NewRule newRule = newRepo.createRule("NPE") + newRepo.createRule("NPE") .setName("Detect NPE") .setHtmlDescription("Detect java.lang.NullPointerException") .setSeverity(Severity.BLOCKER) .setInternalKey("/something") .setStatus(RuleStatus.BETA) - .setDebtSubCharacteristic("COMPILER") - .setEffortToFixDescription("squid.S115.effortToFix") .setTags("one", "two") .addTags("two", "three", "four"); - newRule.setDebtRemediationFunction(newRule.debtRemediationFunctions().linearWithOffset("1h", "10min")); newRepo.createRule("ABC").setName("ABC").setHtmlDescription("ABC"); newRepo.done(); @@ -93,11 +90,6 @@ public class RulesDefinitionTest { assertThat(rule.internalKey()).isEqualTo("/something"); assertThat(rule.template()).isFalse(); assertThat(rule.status()).isEqualTo(RuleStatus.BETA); - assertThat(rule.debtSubCharacteristic()).isEqualTo("COMPILER"); - assertThat(rule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET); - assertThat(rule.debtRemediationFunction().coefficient()).isEqualTo("1h"); - assertThat(rule.debtRemediationFunction().offset()).isEqualTo("10min"); - assertThat(rule.effortToFixDescription()).isEqualTo("squid.S115.effortToFix"); assertThat(rule.toString()).isEqualTo("[repository=findbugs, key=NPE]"); assertThat(rule.repository()).isSameAs(repo); @@ -107,6 +99,29 @@ public class RulesDefinitionTest { assertThat(rule.hashCode()).isEqualTo(rule.hashCode()); } + @Test + public void define_rules_with_technical_debt() { + RulesDefinition.NewRepository newRepo = context.createRepository("common-java", "java"); + RulesDefinition.NewRule newRule = newRepo.createRule("InsufficientBranchCoverage") + .setName("Insufficient branch coverage") + .setHtmlDescription("Insufficient branch coverage by unit tests") + .setSeverity(Severity.MAJOR) + .setDebtSubCharacteristic(RulesDefinition.SubCharacteristics.UNIT_TESTS) + .setEffortToFixDescription("Effort to test one uncovered branch"); + newRule.setDebtRemediationFunction(newRule.debtRemediationFunctions().linearWithOffset("1h", "10min")); + newRepo.done(); + + RulesDefinition.Repository repo = context.repository("common-java"); + assertThat(repo.rules()).hasSize(1); + + RulesDefinition.Rule rule = repo.rule("InsufficientBranchCoverage"); + assertThat(rule.debtSubCharacteristic()).isEqualTo("UNIT_TESTS"); + assertThat(rule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET); + assertThat(rule.debtRemediationFunction().coefficient()).isEqualTo("1h"); + assertThat(rule.debtRemediationFunction().offset()).isEqualTo("10min"); + assertThat(rule.effortToFixDescription()).isEqualTo("Effort to test one uncovered branch"); + } + @Test public void define_rule_with_default_fields() { RulesDefinition.NewRepository newFindbugs = context.createRepository("findbugs", "java"); -- 2.39.5