@Test public void rule_without_key() { List<Rule> rules = parseAnnotatedClass(RuleWithoutKey.class); assertThat(rules).hasSize(1); Rule rule = rules.get(0); assertThat(rule.getKey()).isEqualTo(RuleWithoutKey.class.getCanonicalName()); assertThat(rule.getName()).isEqualTo("foo"); assertThat(rule.getDescription()).isNull(); assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR); }
@Test public void overridden_rule() { List<Rule> rules = parseAnnotatedClass(OverridingRule.class); assertThat(rules).hasSize(1); Rule rule = rules.get(0); assertThat(rule.getKey()).isEqualTo("overriding_foo"); assertThat(rule.getName()).isEqualTo("Overriding Foo"); assertThat(rule.getDescription()).isNull(); assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR); assertThat(rule.getParams()).hasSize(2); }
@Test public void rule_without_name_nor_description() { List<Rule> rules = parseAnnotatedClass(RuleWithoutNameNorDescription.class); assertThat(rules).hasSize(1); Rule rule = rules.get(0); assertThat(rule.getKey()).isEqualTo("foo"); assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR); assertThat(rule.getName()).isNull(); assertThat(rule.getDescription()).isNull(); }
@Test public void rule_with_text_property() { List<Rule> rules = parseAnnotatedClass(RuleWithTextProperty.class); RuleParam prop = rules.get(0).getParam("property"); assertThat(prop.getDescription()).isEqualTo("text"); assertThat(prop.getDefaultValue()).isEqualTo("Long text"); assertThat(prop.getType()).isEqualTo(PropertyType.TEXT.name()); }
@Test public void rule_with_integer_property() { List<Rule> rules = parseAnnotatedClass(RuleWithIntegerProperty.class); RuleParam prop = rules.get(0).getParam("property"); assertThat(prop.getDescription()).isEqualTo("Max"); assertThat(prop.getDefaultValue()).isEqualTo("12"); assertThat(prop.getType()).isEqualTo(PropertyType.INTEGER.name()); }
@Test public void rule_with_property() { List<Rule> rules = parseAnnotatedClass(RuleWithProperty.class); assertThat(rules).hasSize(1); Rule rule = rules.get(0); assertThat(rule.getKey()).isEqualTo("foo"); assertThat(rule.getName()).isEqualTo("bar"); assertThat(rule.getDescription()).isEqualTo("Foo Bar"); assertThat(rule.getSeverity()).isEqualTo(RulePriority.BLOCKER); assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_READY); assertThat(rule.getParams()).hasSize(1); RuleParam prop = rule.getParam("property"); assertThat(prop.getKey()).isEqualTo("property"); assertThat(prop.getDescription()).isEqualTo("Ignore ?"); assertThat(prop.getDefaultValue()).isEqualTo("false"); assertThat(prop.getType()).isEqualTo(PropertyType.STRING.name()); }
@Test public void should_reject_invalid_property_types() { exception.expect(SonarException.class); exception.expectMessage("Invalid property type [INVALID]"); parseAnnotatedClass(RuleWithInvalidPropertyType.class); }