From da764abb1ee6019ba4aef1572ef4bdd8022de3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 13 Jun 2020 22:04:06 +0200 Subject: [PATCH] Convert kotlin tests --- pmd-kotlin/pom.xml | 10 +++ .../pmd/cpd/KotlinTokenizerTest.java | 62 ++++++++----------- .../kotlin/cpd/testdata}/comment.kt | 0 .../kotlin/cpd/testdata}/imports.kt | 0 .../kotlin/cpd/testdata}/increment.kt | 0 5 files changed, 35 insertions(+), 37 deletions(-) rename pmd-kotlin/src/test/resources/net/sourceforge/pmd/{cpd => lang/kotlin/cpd/testdata}/comment.kt (100%) rename pmd-kotlin/src/test/resources/net/sourceforge/pmd/{cpd => lang/kotlin/cpd/testdata}/imports.kt (100%) rename pmd-kotlin/src/test/resources/net/sourceforge/pmd/{cpd => lang/kotlin/cpd/testdata}/increment.kt (100%) diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index 77db6c864e..3d3bd91fed 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -49,10 +49,20 @@ junit test + + org.junit.vintage + junit-vintage-engine + test + net.sourceforge.pmd pmd-test test + + net.sourceforge.pmd + pmd-lang-test + test + diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/cpd/KotlinTokenizerTest.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/cpd/KotlinTokenizerTest.java index 6d45a5bc8b..28231a36d6 100644 --- a/pmd-kotlin/src/test/java/net/sourceforge/pmd/cpd/KotlinTokenizerTest.java +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/cpd/KotlinTokenizerTest.java @@ -4,53 +4,41 @@ package net.sourceforge.pmd.cpd; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; +import java.util.Properties; -import org.apache.commons.io.IOUtils; -import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import net.sourceforge.pmd.testframework.AbstractTokenizerTest; +import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest; -@RunWith(Parameterized.class) -public class KotlinTokenizerTest extends AbstractTokenizerTest { +public class KotlinTokenizerTest extends CpdTextComparisonTest { - private final String filename; - private final int nExpectedTokens; - - public KotlinTokenizerTest(String filename, int nExpectedTokens) { - this.filename = filename; - this.nExpectedTokens = nExpectedTokens; - } - - @Parameterized.Parameters - public static Collection data() { - return Arrays.asList( - new Object[] { "comment.kt", 5 }, - new Object[] { "increment.kt", 185 }, - new Object[] { "imports.kt", 1 } - ); - } - - @Before - @Override - public void buildTokenizer() throws IOException { - this.tokenizer = new KotlinTokenizer(); - this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), this.filename)); + public KotlinTokenizerTest() { + super(".kt"); } @Override - public String getSampleCode() throws IOException { - return IOUtils.toString(KotlinTokenizer.class.getResourceAsStream(this.filename)); + protected String getResourcePrefix() { + return "../lang/kotlin/cpd/testdata"; + } + + @Override + public Tokenizer newTokenizer(Properties properties) { + return new KotlinTokenizer(); } @Test - public void tokenizeTest() throws IOException { - this.expectedTokenCount = nExpectedTokens; - super.tokenizeTest(); + public void testComments() { + doTest("comment"); + } + + + @Test + public void testIncrement() { + doTest("increment"); + } + + @Test + public void testImportsIgnored() { + doTest("imports"); } } diff --git a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/cpd/comment.kt b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/cpd/testdata/comment.kt similarity index 100% rename from pmd-kotlin/src/test/resources/net/sourceforge/pmd/cpd/comment.kt rename to pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/cpd/testdata/comment.kt diff --git a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/cpd/imports.kt b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/cpd/testdata/imports.kt similarity index 100% rename from pmd-kotlin/src/test/resources/net/sourceforge/pmd/cpd/imports.kt rename to pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/cpd/testdata/imports.kt diff --git a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/cpd/increment.kt b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/cpd/testdata/increment.kt similarity index 100% rename from pmd-kotlin/src/test/resources/net/sourceforge/pmd/cpd/increment.kt rename to pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/cpd/testdata/increment.kt