]> source.dussan.org Git - sonarqube.git/commitdiff
Improve rule tag validation message
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 27 Feb 2014 16:22:15 +0000 (17:22 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 27 Feb 2014 17:41:33 +0000 (18:41 +0100)
sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java
sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleDefinitionsTest.java
sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagFormatTest.java
sonar-server/src/main/java/org/sonar/server/rule/RuleTags.java

index 8701e1aa2cf5597740edb997ea395bf7ee241ca0..7d056cd8f4c017184e70c4429a8e355e29b91627 100644 (file)
@@ -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));
     }
   }
 }
index 93af6b0e74542e532e1ab2773a87e8c6382bd2fb..5fb81e7ccab8aee76a6b6a47744dbb84bf77e1c4 100644 (file)
@@ -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, '+', '-', '#', '.'");
     }
   }
 
index 0bb5d18acadab448353245d79c9160646b06a395..d0ad96429aa8ebcc339444e3e3d8122408bd57b0 100644 (file)
@@ -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, '+', '-', '#', '.'");
     }
   }
 }
index c4346ceab9fe417425c23148ab2e3a591b8a5b7b..cf15e4f18d286a7d264f8fda2e1f26edd727cf39 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.server.user.UserSession;
 import java.util.Collection;
 
 /**
- * Used through ruby code <pre>Internal.quality_profiles</pre>
+ * Used through ruby code <pre>Internal.rule_tags</pre>
  */
 public class RuleTags implements ServerExtension {