aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications/src/test/java
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-06 14:08:06 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-06 14:08:06 +0000
commitaeadc1f9129274949daaa57738c7c4550bdfbc7b (patch)
tree08dadf5ef7474fc41d1d48f74648f1ba8b55f34d /sonar-duplications/src/test/java
downloadsonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.tar.gz
sonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.zip
SONAR-236 remove deprecated code from checkstyle plugin + display default value of rule parameters in Q profile console
Diffstat (limited to 'sonar-duplications/src/test/java')
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/cpd/CPDTest.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/cpd/CPDTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/cpd/CPDTest.java
new file mode 100644
index 00000000000..f0f561091b2
--- /dev/null
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/cpd/CPDTest.java
@@ -0,0 +1,90 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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.duplications.cpd;
+
+import net.sourceforge.pmd.cpd.AbstractLanguage;
+import net.sourceforge.pmd.cpd.JavaTokenizer;
+import net.sourceforge.pmd.cpd.TokenEntry;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class CPDTest {
+
+ @Test
+ public void testSetLoadSourceCodeSlicesToFalse() throws IOException {
+ TokenEntry.clearImages();
+ AbstractLanguage cpdLanguage = new AbstractLanguage(new JavaTokenizer()) {
+ };
+ CPD cpd = new CPD(20, cpdLanguage);
+ cpd.setEncoding(Charset.defaultCharset().name());
+ cpd.setLoadSourceCodeSlices(false);
+ cpd.add(new File("test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile1.java"));
+ cpd.add(new File("test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile2.java"));
+ cpd.go();
+
+ List<Match> matches = getMatches(cpd);
+ assertThat(matches.size(), is(1));
+
+ org.sonar.duplications.cpd.Match match = matches.get(0);
+ assertThat(match.getLineCount(), is(26));
+ assertThat(match.getFirstMark().getBeginLine(), is(16));
+ assertThat(match.getSourceCodeSlice(), is(nullValue()));
+ }
+
+ @Test
+ public void testDuplicationOnSameFile() throws IOException {
+ TokenEntry.clearImages();
+ AbstractLanguage cpdLanguage = new AbstractLanguage(new JavaTokenizer()) {
+ };
+ CPD cpd = new CPD(20, cpdLanguage);
+ cpd.setEncoding(Charset.defaultCharset().name());
+ cpd.setLoadSourceCodeSlices(false);
+ cpd.add(new File("test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile3.java"));
+ cpd.go();
+
+ List<Match> matches = getMatches(cpd);
+ assertThat(matches.size(), is(1));
+
+ org.sonar.duplications.cpd.Match match = matches.get(0);
+ assertThat(match.getLineCount(), is(16));
+ assertThat(match.getFirstMark().getBeginLine(), is(29));
+ assertThat(match.getSourceCodeSlice(), is(nullValue()));
+ }
+
+ private List<Match> getMatches(CPD cpd) {
+ List<Match> matches = new ArrayList<org.sonar.duplications.cpd.Match>();
+ Iterator<Match> matchesIter = cpd.getMatches();
+ while (matchesIter.hasNext()) {
+ matches.add(matchesIter.next());
+ }
+ return matches;
+ }
+
+}