aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-11-26 15:58:47 +0000
committerGodin <mandrikov@gmail.com>2010-11-26 15:58:47 +0000
commitf461f118543c44262b0c6639f31fe86d88d20b18 (patch)
treea01d81912ea198e7ba2f6473a6446f49cf8978bf /plugins
parentee7713a87f26b26070f2fb605850d8d0c620489e (diff)
downloadsonarqube-f461f118543c44262b0c6639f31fe86d88d20b18.tar.gz
sonarqube-f461f118543c44262b0c6639f31fe86d88d20b18.zip
SONAR-1817: Add unit test
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/NoSonarCheckTest.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/NoSonarCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/NoSonarCheckTest.java
new file mode 100644
index 00000000000..56a5f55b72b
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/NoSonarCheckTest.java
@@ -0,0 +1,44 @@
+package org.sonar.java.squid.check;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.sonar.java.ast.SquidTestUtils.getFile;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.squid.JavaSquidConfiguration;
+import org.sonar.java.squid.SquidScanner;
+import org.sonar.squid.Squid;
+import org.sonar.squid.api.SourceFile;
+import org.sonar.squid.measures.Metric;
+
+public class NoSonarCheckTest {
+
+ private Squid squid;
+
+ @Before
+ public void setUp() {
+ squid = new Squid(new JavaSquidConfiguration());
+ NoSonarCheck check = new NoSonarCheck();
+ squid.registerVisitor(check);
+ JavaAstScanner scanner = squid.register(JavaAstScanner.class);
+ scanner.scanFile(getFile("/rules/FileWithNOSONARTags.java"));
+ scanner.scanFile(getFile("/rules/FileWithoutNOSONARTags.java"));
+ squid.decorateSourceCodeTreeWith(Metric.values());
+ squid.register(SquidScanner.class).scan();
+ }
+
+ @Test
+ public void testNoSonarTagDetection() {
+ SourceFile file = (SourceFile) squid.search("FileWithNOSONARTags.java");
+ assertThat(file.getCheckMessages().size(), is(2));
+ }
+
+ @Test
+ public void testNoSonarTagDetectionWhenNoTag() {
+ SourceFile file = (SourceFile) squid.search("FileWithoutNOSONARTags.java");
+ assertThat(file.getCheckMessages().size(), is(0));
+ }
+
+}