diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-03-06 09:53:44 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-03-06 12:15:22 +0100 |
commit | fdab089af9a50ab912cbf0061e61f00075a6f264 (patch) | |
tree | 82cfc1040a14f0dcaa8ccd0b7d63c1711298415a /sonar-plugin-api | |
parent | 61445847aa308e79cf92ed308a43e15d165eb788 (diff) | |
download | sonarqube-fdab089af9a50ab912cbf0061e61f00075a6f264.tar.gz sonarqube-fdab089af9a50ab912cbf0061e61f00075a6f264.zip |
SONAR-5056 Set Rule remediation factor and offset as String
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleDefinitions.java | 4 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleDefinitionsTest.java | 35 |
2 files changed, 37 insertions, 2 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleDefinitions.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleDefinitions.java index cbb5f213d1b..a3d952ea567 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleDefinitions.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleDefinitions.java @@ -389,13 +389,13 @@ public interface RuleDefinitions extends ServerExtension { public NewRule setRemediationFactor(@Nullable String remediationFactor) { // TODO validate format - this.remediationFactor = remediationFactor; + this.remediationFactor = StringUtils.deleteWhitespace(remediationFactor); return this; } public NewRule setRemediationOffset(@Nullable String remediationOffset) { // TODO validate format - this.remediationOffset = remediationOffset; + this.remediationOffset = StringUtils.deleteWhitespace(remediationOffset); return this; } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleDefinitionsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleDefinitionsTest.java index a8c57ad30e0..e169b50a7d9 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleDefinitionsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleDefinitionsTest.java @@ -19,6 +19,7 @@ */ package org.sonar.api.server.rule; +import org.junit.Ignore; import org.junit.Test; import org.sonar.api.rule.RemediationFunction; import org.sonar.api.rule.RuleStatus; @@ -168,6 +169,21 @@ public class RuleDefinitionsTest { } @Test + public void sanitize_remediation_factor_and_offset() { + RuleDefinitions.NewRepository newFindbugs = context.newRepository("findbugs", "java"); + newFindbugs.newRule("NPE") + .setName("Detect NPE") + .setHtmlDescription("NPE") + .setRemediationFactor(" 1 h ") + .setRemediationOffset(" 10 mi n "); + newFindbugs.done(); + + RuleDefinitions.Rule npeRule = context.repository("findbugs").rule("NPE"); + assertThat(npeRule.remediationFactor()).isEqualTo("1h"); + assertThat(npeRule.remediationOffset()).isEqualTo("10min"); + } + + @Test public void extend_repository() { assertThat(context.extendedRepositories()).isEmpty(); @@ -301,4 +317,23 @@ public class RuleDefinitionsTest { assertThat(e).hasMessage("Status 'REMOVED' is not accepted on rule '[repository=findbugs, key=NPE]'"); } } + + @Test + @Ignore("TODO") + public void fail_if_bad_remediation_factor_or_offset() { + try { + context.newRepository("findbugs", "java").newRule("NPE").setRemediationFactor("ten hours"); + fail(); + } catch (IllegalArgumentException e) { + assertThat(e).hasMessage("Duration 'ten hours' is invalid, it should use the following sample format : 2d 10h 15min"); + } + + try { + context.newRepository("findbugs", "java").newRule("NPE").setRemediationOffset("ten hours"); + fail(); + } catch (IllegalArgumentException e) { + assertThat(e).hasMessage("Duration 'ten hours' is invalid, it should use the following sample format : 2d 10h 15min"); + } + } + } |