aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-10-25 14:42:24 +0000
committerGodin <mandrikov@gmail.com>2010-10-25 14:42:24 +0000
commitfda319b541eaa63b080da32f6526f4c83e94c416 (patch)
tree8077c79988c3e89fd2523a706a0ef8ad89af6cc1
parentc0f8c39d35ffb7baaad8cc3f7418b2023885fc7d (diff)
downloadsonarqube-fda319b541eaa63b080da32f6526f4c83e94c416.tar.gz
sonarqube-fda319b541eaa63b080da32f6526f4c83e94c416.zip
Add unit test for cloned rules to AnnotationCheckFactory
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java32
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/checks/CheckWithKey.java10
2 files changed, 33 insertions, 9 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java
index 7eec4aaac6a..4c4d4bdafb3 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java
@@ -27,6 +27,9 @@ import org.sonar.api.utils.SonarException;
import java.util.Arrays;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
@@ -37,7 +40,7 @@ public class AnnotationCheckFactoryTest {
public void createCheckWithoutProperties() {
RulesProfile profile = RulesProfile.create("repo", "java");
ActiveRule activeRule = profile.activateRule(Rule.create("repo", "org.sonar.api.checks.CheckWithoutProperties", ""), null);
- AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithoutProperties.class));
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithoutProperties.class));
Object check = factory.getCheck(activeRule);
assertNotNull(check);
@@ -52,7 +55,7 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("pattern", "foo");
- AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithStringProperty.class));
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithStringProperty.class));
Object check = factory.getCheck(activeRule);
assertNotNull(check);
@@ -68,7 +71,7 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("unknown", "bar");
- AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithStringProperty.class));
+ AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithStringProperty.class));
}
@Test
@@ -81,7 +84,7 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("max", "300");
activeRule.setParameter("ignore", "true");
- AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithPrimitiveProperties.class));
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithPrimitiveProperties.class));
Object check = factory.getCheck(activeRule);
assertThat(((CheckWithPrimitiveProperties) check).getMax(), is(300));
@@ -96,13 +99,12 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("max", "300");
- AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithIntegerProperty.class));
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithIntegerProperty.class));
Object check = factory.getCheck(activeRule);
assertThat(((CheckWithIntegerProperty) check).getMax(), is(300));
}
-
@Test(expected = SonarException.class)
public void failIfPropertyTypeIsNotSupported() {
RulesProfile profile = RulesProfile.create("repo", "java");
@@ -111,7 +113,7 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("max", "300");
- AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithUnsupportedPropertyType.class));
+ AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithUnsupportedPropertyType.class));
}
@Test
@@ -122,10 +124,22 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("maximum", "300");
- AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithOverriddenPropertyKey.class));
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithOverriddenPropertyKey.class));
Object check = factory.getCheck(activeRule);
assertThat(((CheckWithOverriddenPropertyKey) check).getMax(), is(300));
}
-}
+ @Test
+ public void shouldWorkWithClonedRules() {
+ RulesProfile profile = RulesProfile.create("repo", "java");
+ Rule rule = Rule.create("repo", "CheckWithKey", "");
+ Rule clonedRule = Rule.create("repo", "CheckWithKey_2", "").setParent(rule);
+
+ profile.activateRule(rule, null);
+ profile.activateRule(clonedRule, null);
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithKey.class));
+
+ assertThat(factory.getChecks(), not(hasItems(nullValue())));
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/checks/CheckWithKey.java b/sonar-plugin-api/src/test/java/org/sonar/api/checks/CheckWithKey.java
new file mode 100644
index 00000000000..9cd020d1404
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/checks/CheckWithKey.java
@@ -0,0 +1,10 @@
+package org.sonar.api.checks;
+
+import org.sonar.check.IsoCategory;
+import org.sonar.check.Priority;
+import org.sonar.check.Rule;
+
+@Rule(key = "CheckWithKey", isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL)
+public class CheckWithKey {
+
+}