*/
package org.sonar.api.rules;
-import com.google.common.collect.Lists;
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.List;
+
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.check.Check;
-import java.lang.reflect.Field;
-import java.util.Collection;
-import java.util.List;
+import com.google.common.collect.Lists;
/**
* @since 2.3
private Rule toRule(String repositoryKey, Class clazz, org.sonar.check.Rule ruleAnnotation) {
String ruleKey = StringUtils.defaultIfEmpty(ruleAnnotation.key(), clazz.getCanonicalName());
- String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), ruleKey);
+ String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), null);
+ String description = StringUtils.defaultIfEmpty(ruleAnnotation.description(), null);
Rule rule = Rule.create(repositoryKey, ruleKey, ruleName);
- rule.setDescription(ruleAnnotation.description());
+ rule.setDescription(description);
rule.setSeverity(RulePriority.fromCheckPriority(ruleAnnotation.priority()));
rule.setCardinality(ruleAnnotation.cardinality());
*/
package org.sonar.api.rules;
-import org.junit.Test;
-import org.sonar.check.IsoCategory;
-import org.sonar.check.Priority;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
import java.util.Collections;
import java.util.List;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import org.junit.Test;
+import org.sonar.check.IsoCategory;
+import org.sonar.check.Priority;
public class AnnotationRuleParserTest {
Rule rule = rules.get(0);
assertThat(rule.getKey(), is("foo"));
assertThat(rule.getName(), is("bar"));
+ assertThat(rule.getDescription(), is("Foo Bar"));
assertThat(rule.getSeverity(), is(RulePriority.BLOCKER));
assertThat(rule.getParams().size(), is(1));
RuleParam prop = rule.getParam("property");
}
@Test
- public void ruleWithoutName() {
- List<Rule> rules = parseAnnotatedClass(RuleWithoutName.class);
+ public void ruleWithoutNameNorDescription() {
+ List<Rule> rules = parseAnnotatedClass(RuleWithoutNameNorDescription.class);
assertThat(rules.size(), is(1));
Rule rule = rules.get(0);
assertThat(rule.getKey(), is("foo"));
- assertThat(rule.getName(), is("foo"));
assertThat(rule.getSeverity(), is(RulePriority.MAJOR));
+ assertThat(rule.getName(), is(nullValue()));
+ assertThat(rule.getDescription(), is(nullValue()));
}
@Test
Rule rule = rules.get(0);
assertThat(rule.getKey(), is(RuleWithoutKey.class.getCanonicalName()));
assertThat(rule.getName(), is("foo"));
+ assertThat(rule.getDescription(), is(nullValue()));
assertThat(rule.getSeverity(), is(RulePriority.MAJOR));
}
}
@org.sonar.check.Rule(key = "foo")
- private class RuleWithoutName {
+ private class RuleWithoutNameNorDescription {
}
- @org.sonar.check.Rule(key = "foo", name = "bar", priority = Priority.BLOCKER)
+ @org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", priority = Priority.BLOCKER)
private class RuleWithProperty {
@org.sonar.check.RuleProperty(description = "Ignore ?", defaultValue = "false")
String property;