aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-squid-java-plugin/src/test/java/org
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-04-12 09:50:48 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-04-12 10:04:58 +0200
commit3f782b64d76ebb1de03e8eb6d1f902a6bbba63de (patch)
treed510784206f9237e0e6a8ada06537f6d86395334 /plugins/sonar-squid-java-plugin/src/test/java/org
parentd6693ffe167bb5d92aaddbd28ff3780a7494f54d (diff)
downloadsonarqube-3f782b64d76ebb1de03e8eb6d1f902a6bbba63de.tar.gz
sonarqube-3f782b64d76ebb1de03e8eb6d1f902a6bbba63de.zip
SONAR-2349 New rule to detect empty Java files
Diffstat (limited to 'plugins/sonar-squid-java-plugin/src/test/java/org')
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/EmptyFileCheckTest.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/EmptyFileCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/EmptyFileCheckTest.java
new file mode 100644
index 00000000000..358dc657b29
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/EmptyFileCheckTest.java
@@ -0,0 +1,66 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+
+package org.sonar.java.squid.check;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
+import org.sonar.java.squid.JavaSquidConfiguration;
+import org.sonar.java.squid.SquidScanner;
+import org.sonar.squid.Squid;
+import org.sonar.squid.api.CheckMessage;
+import org.sonar.squid.api.SourceFile;
+import org.sonar.squid.measures.Metric;
+
+public class EmptyFileCheckTest {
+ private Squid squid;
+
+ @Before
+ public void setUp() {
+ squid = new Squid(new JavaSquidConfiguration());
+ EmptyFileCheck check = new EmptyFileCheck();
+ squid.registerVisitor(check);
+ JavaAstScanner scanner = squid.register(JavaAstScanner.class);
+ scanner.scanDirectory(SquidTestUtils.getFile("/metrics/commentedCode"));
+ squid.decorateSourceCodeTreeWith(Metric.values());
+ squid.register(SquidScanner.class).scan();
+ }
+
+ @Test
+ public void shouldDetectEmptyFiles() {
+ SourceFile file = (SourceFile) squid.search("org/foo/CommentedOutFile.java");
+ assertThat(file.getCheckMessages().size(), is(1));
+ CheckMessage message = file.getCheckMessages().iterator().next();
+ assertThat(message.getLine(), nullValue());
+ assertThat(message.getDefaultMessage(), is("This Java file is empty"));
+ }
+
+ @Test
+ public void shouldNotLogOnCorrectFiles() {
+ SourceFile file = (SourceFile) squid.search("CommentedCode.java");
+ assertThat(file.getCheckMessages().size(), is(0));
+ }
+}