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));
}
}
}
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;
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");
}
}
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]");
}
}
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");
}
}
// 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, '+', '-', '#', '.'");
}
}
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, '+', '-', '#', '.'");
}
}
}