}
private void validateRule(Rule rule, String repositoryKey) {
- if (rule.getName() == null && ruleI18nManager.getName(repositoryKey, rule.getKey(), Locale.ENGLISH) == null) {
+ if (StringUtils.isBlank(rule.getName()) && StringUtils.isBlank(ruleI18nManager.getName(repositoryKey, rule.getKey(), Locale.ENGLISH))) {
throw new SonarException("The following rule (repository: " + repositoryKey + ") must have a name: " + rule);
}
- if (rule.getDescription() == null && ruleI18nManager.getDescription(repositoryKey, rule.getKey(), Locale.ENGLISH) == null) {
- if (rule.getName() != null && ruleI18nManager.getName(repositoryKey, rule.getKey(), Locale.ENGLISH) == null) {
+ if (StringUtils.isBlank(rule.getDescription()) && StringUtils.isBlank(ruleI18nManager.getDescription(repositoryKey, rule.getKey(), Locale.ENGLISH))) {
+ if (StringUtils.isNotBlank(rule.getName()) && StringUtils.isBlank(ruleI18nManager.getName(repositoryKey, rule.getKey(), Locale.ENGLISH))) {
// specific case
throw new SonarException("No description found for the rule '" + rule.getName() + "' (repository: " + repositoryKey + ") because the entry 'rule."
+ repositoryKey + "." + rule.getKey() + ".name' is missing from the bundle.");
assertThat(result.size(), is(VolumeRepository.SIZE));
}
- // http://jira.codehaus.org/browse/SONAR-3305
+ // SONAR-3305
@Test
public void shouldFailRuleWithoutName() throws Exception {
RuleI18nManager ruleI18nManager = mock(RuleI18nManager.class);
task.start();
}
- // http://jira.codehaus.org/browse/SONAR-3305
+ // SONAR-3769
+ @Test
+ public void shouldFailRuleWithBlankName() throws Exception {
+ RuleI18nManager ruleI18nManager = mock(RuleI18nManager.class);
+ when(ruleI18nManager.getName(anyString(), anyString(), any(Locale.class))).thenReturn("");
+ task = new RegisterRules(getSessionFactory(), new RuleRepository[] {new RuleWithoutNameRepository()}, ruleI18nManager);
+ setupData("shared");
+
+ // the rule has no name, it should fail
+ try {
+ task.start();
+ fail("Rule must have a name");
+ } catch (SonarException e) {
+ assertThat(e.getMessage(), containsString("must have a name"));
+ }
+ }
+
+ // SONAR-3305
@Test
public void shouldFailRuleWithoutDescription() throws Exception {
RuleI18nManager ruleI18nManager = mock(RuleI18nManager.class);