aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications/test-resources
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/test-resources
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/test-resources')
-rw-r--r--sonar-duplications/test-resources/README.txt2
-rw-r--r--sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile1.java41
-rw-r--r--sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile2.java41
-rw-r--r--sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile3.java63
4 files changed, 147 insertions, 0 deletions
diff --git a/sonar-duplications/test-resources/README.txt b/sonar-duplications/test-resources/README.txt
new file mode 100644
index 00000000000..3f09e6215df
--- /dev/null
+++ b/sonar-duplications/test-resources/README.txt
@@ -0,0 +1,2 @@
+This directory is a workaround for opening the project into Intellij Idea.
+Indeed it tries to compile Java sources found in src/test/resources, and fail because of syntax errors or specific encoding. \ No newline at end of file
diff --git a/sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile1.java b/sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile1.java
new file mode 100644
index 00000000000..75e2b77b0dc
--- /dev/null
+++ b/sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile1.java
@@ -0,0 +1,41 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+package net.sourceforge.pmd.cpd.fork;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import net.sourceforge.pmd.cpd.CPDListener;
+import net.sourceforge.pmd.cpd.CPDNullListener;
+import net.sourceforge.pmd.cpd.Language;
+import net.sourceforge.pmd.cpd.SourceCode;
+import net.sourceforge.pmd.cpd.Tokens;
+import org.sonar.duplications.cpd.MatchAlgorithm;
+
+public class CPDFile1 {
+
+ private Map<String, SourceCode> source = new HashMap<String, SourceCode>();
+ private CPDListener listener = new CPDNullListener();
+ private Tokens tokens = new Tokens();
+ private int minimumTileSize;
+ private MatchAlgorithm matchAlgorithm;
+ private Language language;
+ private boolean skipDuplicates;
+ public static boolean debugEnable = false;
+ private boolean loadSourceCodeSlices = true;
+ private String encoding = System.getProperty("file.encoding");
+
+ public CPD(int minimumTileSize, Language language) {
+ this.minimumTileSize = minimumTileSize;
+ this.language = language;
+ }
+
+ public void skipDuplicates() {
+ this.skipDuplicates = true;
+ }
+
+ public void setCpdListener(CPDListener cpdListener) {
+ this.listener = cpdListener;
+ }
+}
diff --git a/sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile2.java b/sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile2.java
new file mode 100644
index 00000000000..cdd67488f6a
--- /dev/null
+++ b/sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile2.java
@@ -0,0 +1,41 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+package net.sourceforge.pmd.cpd.fork;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import net.sourceforge.pmd.cpd.CPDListener;
+import net.sourceforge.pmd.cpd.CPDNullListener;
+import net.sourceforge.pmd.cpd.Language;
+import net.sourceforge.pmd.cpd.SourceCode;
+import net.sourceforge.pmd.cpd.Tokens;
+import org.sonar.duplications.cpd.MatchAlgorithm;
+
+public class CPDFile2 {
+
+ private Map<String, SourceCode> source = new HashMap<String, SourceCode>();
+ private CPDListener listener = new CPDNullListener();
+ private Tokens tokens = new Tokens();
+ private int minimumTileSize;
+ private MatchAlgorithm matchAlgorithm;
+ private Language language;
+ private boolean skipDuplicates;
+ public static boolean debugEnable = false;
+ private boolean loadSourceCodeSlices = true;
+ private String encoding = System.getProperty("file.encoding");
+
+ public CPD(int minimumTileSize, Language language) {
+ this.minimumTileSize = minimumTileSize;
+ this.language = language;
+ }
+
+ public void skipDuplicates() {
+ this.skipDuplicates = true;
+ }
+
+ public void setCpdListener(CPDListener cpdListener) {
+ this.listener = cpdListener;
+ }
+}
diff --git a/sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile3.java b/sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile3.java
new file mode 100644
index 00000000000..8ba22b82a07
--- /dev/null
+++ b/sonar-duplications/test-resources/org/sonar/duplications/cpd/CPDTest/CPDFile3.java
@@ -0,0 +1,63 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+package net.sourceforge.pmd.cpd.fork;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.sourceforge.pmd.cpd.CPDListener;
+import net.sourceforge.pmd.cpd.CPDNullListener;
+import net.sourceforge.pmd.cpd.Language;
+import net.sourceforge.pmd.cpd.SourceCode;
+import net.sourceforge.pmd.cpd.Tokens;
+
+import org.apache.commons.io.FileUtils;
+import org.sonar.duplications.cpd.CPD;
+import org.sonar.duplications.cpd.Match;
+import org.sonar.duplications.cpd.MatchAlgorithm;
+
+public class CPDFile2 {
+
+
+ public void method1(){
+ CPD cpd = new CPD(20, cpdLanguage);
+ cpd.setEncoding(Charset.defaultCharset().name());
+ cpd.setLoadSourceCodeSlices(false);
+ cpd.add(FileUtils.toFile(CPD.class.getResource("/org/sonar/duplications/cpd/CPDTest/CPDFile1.java")));
+ cpd.add(FileUtils.toFile(CPD.class.getResource("/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()));
+ }
+
+ public void method1Duplicated(){
+ CPD cpd = new CPD(20, cpdLanguage);
+ cpd.setEncoding(Charset.defaultCharset().name());
+ cpd.setLoadSourceCodeSlices(false);
+ cpd.add(FileUtils.toFile(CPD.class.getResource("/org/sonar/duplications/cpd/CPDTest/CPDFile1.java")));
+ cpd.add(FileUtils.toFile(CPD.class.getResource("/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()));
+ }
+
+}