]> source.dussan.org Git - sonarqube.git/commitdiff
Add unit test for cloned rules to AnnotationCheckFactory
authorGodin <mandrikov@gmail.com>
Mon, 25 Oct 2010 14:42:24 +0000 (14:42 +0000)
committerGodin <mandrikov@gmail.com>
Mon, 25 Oct 2010 14:42:24 +0000 (14:42 +0000)
sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java
sonar-plugin-api/src/test/java/org/sonar/api/checks/CheckWithKey.java [new file with mode: 0644]

index 7eec4aaac6aff342c483b92d8b04f71ca3b8f1bf..4c4d4bdafb39c7afdcd3464221fcc77e6364c3fb 100644 (file)
@@ -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 (file)
index 0000000..9cd020d
--- /dev/null
@@ -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 {
+
+}