aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-02-27 17:22:15 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-02-27 18:41:33 +0100
commitb9f637c91b4e65a7f5a30ffaec82edf539ee1007 (patch)
tree544ebe8479ec19ec68ae20aacb383d5b7117a174 /sonar-plugin-api
parentf4b56a5423ef9bc5a6dfced3a91024579d351e77 (diff)
downloadsonarqube-b9f637c91b4e65a7f5a30ffaec82edf539ee1007.tar.gz
sonarqube-b9f637c91b4e65a7f5a30ffaec82edf539ee1007.zip
Improve rule tag validation message
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleDefinitionsTest.java19
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagFormatTest.java2
3 files changed, 12 insertions, 11 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java
index 8701e1aa2cf..7d056cd8f4c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java
@@ -40,7 +40,7 @@ public class RuleTagFormat {
public static void validate(String tag) {
if (!isValid(tag)) {
- throw new IllegalArgumentException(String.format("Rule tags accept only the following characters: a-z, 0-9, '+', '-', '#', '.' - '%s'", tag));
+ throw new IllegalArgumentException(String.format("Tag '%s' is invalid. Rule tags accept only the following characters: a-z, 0-9, '+', '-', '#', '.'", tag));
}
}
}
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 93af6b0e745..5fb81e7ccab 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
@@ -20,8 +20,8 @@
package org.sonar.api.server.rule;
import org.junit.Test;
-import org.sonar.api.rule.Severity;
import org.sonar.api.rule.RuleStatus;
+import org.sonar.api.rule.Severity;
import java.net.URL;
@@ -184,8 +184,8 @@ public class RuleDefinitionsTest {
try {
context.newRepository("findbugs", "whatever_the_language").done();
fail();
- } catch (IllegalStateException e) {
- assertThat(e).hasMessage("The rule repository 'findbugs' is defined several times");
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("The rule repository 'findbugs' is defined several times");
}
}
@@ -204,8 +204,8 @@ public class RuleDefinitionsTest {
try {
rule.newParam("level");
fail();
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessage("The parameter 'level' is declared several times on the rule [repository=findbugs, key=NPE]");
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("The parameter 'level' is declared several times on the rule [repository=findbugs, key=NPE]");
}
}
@@ -216,8 +216,8 @@ public class RuleDefinitionsTest {
try {
newRepository.done();
fail();
- } catch (IllegalStateException e) {
- assertThat(e).hasMessage("Name of rule [repository=findbugs, key=NPE] is empty");
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Name of rule [repository=findbugs, key=NPE] is empty");
}
}
@@ -227,8 +227,9 @@ public class RuleDefinitionsTest {
// whitespaces are not allowed in tags
context.newRepository("findbugs", "java").newRule("NPE").setTags("coding style");
fail();
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessage("Rule tags accept only the following characters: a-z, 0-9, '+', '-', '#', '.' - 'coding style'");
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Tag 'coding style' is invalid. Rule tags accept only the following characters: a-z, 0-9, '+', '-', '#', '.'");
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagFormatTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagFormatTest.java
index 0bb5d18acad..d0ad96429aa 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagFormatTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagFormatTest.java
@@ -53,7 +53,7 @@ public class RuleTagFormatTest {
RuleTagFormat.validate(" ");
fail();
} catch (IllegalArgumentException e) {
- assertThat(e).hasMessage("Rule tags accept only the following characters: a-z, 0-9, '+', '-', '#', '.' - ' '");
+ assertThat(e).hasMessage("Tag ' ' is invalid. Rule tags accept only the following characters: a-z, 0-9, '+', '-', '#', '.'");
}
}
}