aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-03-17 09:27:56 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-03-17 09:27:56 +0100
commitbdbbb1b3b8aaa7d4f5d048fa8d20edbca90b38f8 (patch)
treecab24a51b3ec0a468d610198d6546581fd434956
parentb8b3fa6d7437eed7f57878070ac57f746a4c8a12 (diff)
downloadsonarqube-bdbbb1b3b8aaa7d4f5d048fa8d20edbca90b38f8.tar.gz
sonarqube-bdbbb1b3b8aaa7d4f5d048fa8d20edbca90b38f8.zip
SONAR-5056 Fail if not both characteristic and function are defined
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java3
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java27
2 files changed, 30 insertions, 0 deletions
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 6825c6afb6f..662841909d3 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
@@ -439,6 +439,9 @@ public interface RulesDefinition extends ServerExtension {
if (StringUtils.isBlank(htmlDescription)) {
throw new IllegalStateException(String.format("HTML description of rule %s is empty", this));
}
+ if ((StringUtils.isBlank(debtCharacteristic) && debtRemediationFunction != null) || (!StringUtils.isBlank(debtCharacteristic) && debtRemediationFunction == null)) {
+ throw new IllegalStateException(String.format("Both debt characteristic and debt remediation function should be defined on rule '%s'", 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 29d3f6c7f3a..594a14e450d 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
@@ -294,4 +294,31 @@ public class RulesDefinitionTest {
}
}
+ @Test
+ public void fail_if_define_characteristic_without_function() {
+ RulesDefinition.NewRepository newRepository = context.createRepository("findbugs", "java");
+ newRepository.createRule("NPE").setName("NPE").setHtmlDescription("Detect <code>java.lang.NullPointerException</code>")
+ .setDebtCharacteristic("COMPILER");
+ try {
+ newRepository.done();
+ fail();
+ } catch (IllegalStateException e) {
+ assertThat(e).hasMessage("Both debt characteristic and debt remediation function should be defined on rule '[repository=findbugs, key=NPE]'");
+ }
+ }
+
+ @Test
+ public void fail_if_define_function_without_characteristic() {
+ RulesDefinition.NewRepository newRepository = context.createRepository("findbugs", "java");
+ newRepository.createRule("NPE").setName("NPE").setHtmlDescription("Detect <code>java.lang.NullPointerException</code>")
+ .setDebtCharacteristic("")
+ .setDebtRemediationFunction(DebtRemediationFunction.create(DebtRemediationFunction.Type.LINEAR_OFFSET, "1h", "10min"));
+ try {
+ newRepository.done();
+ fail();
+ } catch (IllegalStateException e) {
+ assertThat(e).hasMessage("Both debt characteristic and debt remediation function should be defined on rule '[repository=findbugs, key=NPE]'");
+ }
+ }
+
}