From f1ee39b1f59728b0f19f0eb20875684540455a86 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 Jan 2023 10:26:49 +0100 Subject: [PATCH] Migrate remaining tests to JUnit5 --- .../test/java/net/sourceforge/pmd/cli/CpdCliTest.java | 8 ++++---- .../net/sourceforge/pmd/cli/ForceLanguageCliTest.java | 8 ++++---- .../java/net/sourceforge/pmd/RuleSetFactoryTest.java | 2 +- .../test/java/net/sourceforge/pmd/cli/ZipFileTest.java | 10 +++++----- .../java/net/sourceforge/pmd/cpd/CPDReportTest.java | 10 +++++----- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java b/pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java index 5107c86b99..48ae61586c 100644 --- a/pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java +++ b/pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java @@ -191,7 +191,7 @@ class CpdCliTest extends BaseCliTest { * See: https://sourceforge.net/p/pmd/bugs/1178/ */ @Test - public void testSkipLexicalErrors() throws Exception { + void testSkipLexicalErrors() throws Exception { runCli(VIOLATIONS_FOUND, "--minimum-tokens", "10", "-d", BASE_RES_PATH + "badandgood/", @@ -205,21 +205,21 @@ class CpdCliTest extends BaseCliTest { @Test - public void jsShouldFindDuplicatesWithDifferentFileExtensions() throws Exception { + void jsShouldFindDuplicatesWithDifferentFileExtensions() throws Exception { runCli(VIOLATIONS_FOUND, "--minimum-tokens", "5", "--language", "js", "-d", BASE_RES_PATH + "tsFiles/File1.ts", BASE_RES_PATH + "tsFiles/File2.ts") .checkStdOut(containsString("Found a 9 line (32 tokens) duplication in the following files")); } @Test - public void jsShouldFindNoDuplicatesWithDifferentFileExtensions() throws Exception { + void jsShouldFindNoDuplicatesWithDifferentFileExtensions() throws Exception { runCli(OK, "--minimum-tokens", "5", "--language", "js", "-d", BASE_RES_PATH + "tsFiles/") .checkStdOut(emptyString()); } @Test - public void renderEmptyReportXml() throws Exception { + void renderEmptyReportXml() throws Exception { runCli(OK, "--minimum-tokens", "5", "--language", "js", "-f", "xml", "-d", BASE_RES_PATH + "tsFiles/") diff --git a/pmd-cli/src/test/java/net/sourceforge/pmd/cli/ForceLanguageCliTest.java b/pmd-cli/src/test/java/net/sourceforge/pmd/cli/ForceLanguageCliTest.java index c3fe2cc605..faa57c1f40 100644 --- a/pmd-cli/src/test/java/net/sourceforge/pmd/cli/ForceLanguageCliTest.java +++ b/pmd-cli/src/test/java/net/sourceforge/pmd/cli/ForceLanguageCliTest.java @@ -13,7 +13,7 @@ import java.util.List; import org.junit.jupiter.api.Test; -public class ForceLanguageCliTest extends BaseCliTest { +class ForceLanguageCliTest extends BaseCliTest { private static final String BASE_DIR = "src/test/resources/net/sourceforge/pmd/cli/forceLanguage/"; private static final String RULE_MESSAGE = "Violation from ReportAllRootNodes"; @@ -29,19 +29,19 @@ public class ForceLanguageCliTest extends BaseCliTest { } @Test - public void analyzeSingleXmlWithoutForceLanguage() throws Exception { + void analyzeSingleXmlWithoutForceLanguage() throws Exception { runCli(OK, "-d", BASE_DIR + "src/file1.ext") .verify(r -> r.checkStdOut(containsStringNTimes(0, RULE_MESSAGE))); } @Test - public void analyzeSingleXmlWithForceLanguage() throws Exception { + void analyzeSingleXmlWithForceLanguage() throws Exception { runCli(VIOLATIONS_FOUND, "-d", BASE_DIR + "src/file1.ext", "--force-language", "dummy") .verify(r -> r.checkStdOut(containsStringNTimes(1, RULE_MESSAGE))); } @Test - public void analyzeDirectoryWithForceLanguage() throws Exception { + void analyzeDirectoryWithForceLanguage() throws Exception { runCli(VIOLATIONS_FOUND, "-d", BASE_DIR + "src/", "--force-language", "dummy") .verify(r -> r.checkStdOut(containsStringNTimes(3, RULE_MESSAGE))); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java index 741fccc570..b0940021fb 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java @@ -213,7 +213,7 @@ class RuleSetFactoryTest extends RulesetFactoryTestBase { * @see [java] TestClassWithoutTestCases - can not set test pattern to empty #4279 */ @Test - public void testEmptyStringProperty() { + void testEmptyStringProperty() { Rule r = loadFirstRule("\n" + "\n " + " ruleset desc\n " diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cli/ZipFileTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cli/ZipFileTest.java index e260f65f9d..7df3aba6de 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cli/ZipFileTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cli/ZipFileTest.java @@ -12,20 +12,20 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import net.sourceforge.pmd.PMDConfiguration; import net.sourceforge.pmd.PmdAnalysis; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.util.IOUtil; -public class ZipFileTest { +class ZipFileTest { private static final String ZIP_PATH = "src/test/resources/net/sourceforge/pmd/cli/zipWithSources.zip"; private final Path zipPath = Paths.get(ZIP_PATH); @Test - public void testZipFile() { + void testZipFile() { PMDConfiguration conf = new PMDConfiguration(); conf.addInputPath(zipPath); // no relativizeRoot paths configured -> we use the relative path @@ -40,7 +40,7 @@ public class ZipFileTest { } @Test - public void testZipFileRelativizeWith() { + void testZipFileRelativizeWith() { PMDConfiguration conf = new PMDConfiguration(); conf.addInputPath(zipPath); conf.addRelativizeRoot(Paths.get("src/test/resources")); @@ -55,7 +55,7 @@ public class ZipFileTest { } @Test - public void testZipFileRelativizeWithRoot() { + void testZipFileRelativizeWithRoot() { PMDConfiguration conf = new PMDConfiguration(); conf.addInputPath(zipPath); // this configures "/" as the relativizeRoot -> result are absolute paths diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDReportTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDReportTest.java index e888146e36..744bdfdd18 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDReportTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDReportTest.java @@ -4,8 +4,8 @@ package net.sourceforge.pmd.cpd; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.HashMap; @@ -14,14 +14,14 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import net.sourceforge.pmd.util.Predicate; -public class CPDReportTest { +class CPDReportTest { @Test - public void testFilterMatches() { + void testFilterMatches() { List originalMatches = Arrays.asList( createMatch("file1.java", "file2.java", 1), createMatch("file1.java", "file3.java", 2),