[core] Convert *FingerPrinterTests to JUnit5

This commit is contained in:
Andreas Dangel committed 2022-05-19 16:36:08 +02:00
1 parent 0e51007d32
commit eee9f6de38
7 files changed
+194 -193

No files matched your search

@@ -21,7 +21,7 @@ import org.junit.jupiter.api.AfterAll;
import net.sourceforge.pmd.internal.Slf4jSimpleConfiguration;
public class AbstractAntTest {
class AbstractAntTest {
protected Project project;
protected StringBuilder log;
@@ -39,7 +39,7 @@ public class AbstractAntTest {
}
@AfterAll
public static void resetLogging() {
static void resetLogging() {
Slf4jSimpleConfiguration.reconfigureDefaultLogLevel(null);
}
@@ -18,12 +18,12 @@ import org.junit.jupiter.api.Test;
public class CPDTaskTest extends AbstractAntTest {
@BeforeEach
public void setUp() {
void setUp() {
configureProject("src/test/resources/net/sourceforge/pmd/ant/xml/cpdtasktest.xml");
}
@Test
public void testBasic() {
void testBasic() {
executeTarget("testBasic");
// FIXME: This clearly needs to be improved - but I don't like to write
// test, so feel free to contribute :)
@@ -18,12 +18,12 @@ import org.junit.jupiter.api.Test;
public class PMDTaskTest extends AbstractAntTest {
@BeforeEach
public void setUp() {
void setUp() {
configureProject("src/test/resources/net/sourceforge/pmd/ant/xml/pmdtasktest.xml");
}
@Test
public void testFormatterWithNoToFileAttribute() {
void testFormatterWithNoToFileAttribute() {
try {
executeTarget("testFormatterWithNoToFileAttribute");
Assertions.fail("This should throw an exception");
@@ -33,7 +33,7 @@ public class PMDTaskTest extends AbstractAntTest {
}
@Test
public void testNoRuleSets() {
void testNoRuleSets() {
try {
executeTarget("testNoRuleSets");
Assertions.fail("This should throw an exception");
@@ -43,12 +43,12 @@ public class PMDTaskTest extends AbstractAntTest {
}
@Test
public void testBasic() {
void testBasic() {
executeTarget("testBasic");
}
@Test
public void testInvalidLanguageVersion() {
void testInvalidLanguageVersion() {
try {
executeTarget("testInvalidLanguageVersion");
Assertions.assertEquals(
@@ -63,7 +63,7 @@ public class PMDTaskTest extends AbstractAntTest {
}
@Test
public void testWithShortFilenames() throws IOException {
void testWithShortFilenames() throws IOException {
executeTarget("testWithShortFilenames");
try (InputStream in = new FileInputStream("target/pmd-ant-test.txt")) {
@@ -75,7 +75,7 @@ public class PMDTaskTest extends AbstractAntTest {
}
@Test
public void testXmlFormatter() throws IOException {
void testXmlFormatter() throws IOException {
executeTarget("testXmlFormatter");
try (InputStream in = new FileInputStream("target/pmd-ant-xml.xml");
File diff suppressed because it is too large. Load diff
@@ -7,30 +7,29 @@ package net.sourceforge.pmd.cache.internal;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.Path;
import java.util.zip.Adler32;
import java.util.zip.Checksum;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
abstract class AbstractClasspathEntryFingerprinterTest {
@RunWith(JUnitParamsRunner.class)
public abstract class AbstractClasspathEntryFingerprinterTest {
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
@TempDir
Path tempDir;
protected ClasspathEntryFingerprinter fingerprinter = newFingerPrinter();
protected Checksum checksum = new Adler32();
@Before
public void setUp() {
@BeforeEach
void setUp() {
checksum.reset();
}
@@ -43,37 +42,37 @@ public abstract class AbstractClasspathEntryFingerprinterTest {
protected abstract File createValidNonEmptyFile() throws IOException;
@Test
public void appliesToNullIsSafe() {
void appliesToNullIsSafe() {
fingerprinter.appliesTo(null);
}
@Parameters(method = "getValidFileExtensions")
@Test
public void appliesToValidFile(final String extension) {
Assert.assertTrue(fingerprinter.appliesTo(extension));
@ParameterizedTest
@MethodSource("getValidFileExtensions")
void appliesToValidFile(final String extension) {
Assertions.assertTrue(fingerprinter.appliesTo(extension));
}
@Parameters(method = "getInvalidFileExtensions")
@Test
public void doesNotApplyToInvalidFile(final String extension) {
Assert.assertFalse(fingerprinter.appliesTo(extension));
@ParameterizedTest
@MethodSource("getInvalidFileExtensions")
void doesNotApplyToInvalidFile(final String extension) {
Assertions.assertFalse(fingerprinter.appliesTo(extension));
}
@Test
public void fingerprintNonExistingFile() throws MalformedURLException, IOException {
void fingerprintNonExistingFile() throws MalformedURLException, IOException {
final long prevValue = checksum.getValue();
fingerprinter.fingerprint(new File("non-existing").toURI().toURL(), checksum);
Assert.assertEquals(prevValue, checksum.getValue());
Assertions.assertEquals(prevValue, checksum.getValue());
}
@Test
public void fingerprintExistingValidFile() throws IOException {
void fingerprintExistingValidFile() throws IOException {
final long prevValue = checksum.getValue();
final File file = createValidNonEmptyFile();
Assert.assertNotEquals(prevValue, updateFingerprint(file));
Assertions.assertNotEquals(prevValue, updateFingerprint(file));
}
protected long updateFingerprint(final File file) throws MalformedURLException, IOException {
@@ -10,7 +10,7 @@ import java.nio.charset.StandardCharsets;
import com.google.common.io.Files;
public class RawFileFingerprinterTest extends AbstractClasspathEntryFingerprinterTest {
class RawFileFingerprinterTest extends AbstractClasspathEntryFingerprinterTest {
@Override
protected ClasspathEntryFingerprinter newFingerPrinter() {
@@ -29,7 +29,7 @@ public class RawFileFingerprinterTest extends AbstractClasspathEntryFingerprinte
@Override
protected File createValidNonEmptyFile() throws IOException {
final File file = tempFolder.newFile("Foo.class");
File file = tempDir.resolve("Foo.class").toFile();
Files.write("some content", file, StandardCharsets.UTF_8);
return file;
@@ -15,13 +15,13 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class ZipFileFingerprinterTest extends AbstractClasspathEntryFingerprinterTest {
class ZipFileFingerprinterTest extends AbstractClasspathEntryFingerprinterTest {
@Test
public void zipEntryMetadataDoesNotAffectFingerprint() throws IOException {
void zipEntryMetadataDoesNotAffectFingerprint() throws IOException {
final File file = createValidNonEmptyFile();
final long baselineFingerprint = getBaseLineFingerprint(file);
final long originalFileSize = file.length();
@@ -35,8 +35,8 @@ public class ZipFileFingerprinterTest extends AbstractClasspathEntryFingerprinte
overwriteZipFileContents(file, zipEntry);
}
Assert.assertEquals(baselineFingerprint, updateFingerprint(file));
Assert.assertNotEquals(originalFileSize, file.length());
Assertions.assertEquals(baselineFingerprint, updateFingerprint(file));
Assertions.assertNotEquals(originalFileSize, file.length());
}
@Override
@@ -56,7 +56,7 @@ public class ZipFileFingerprinterTest extends AbstractClasspathEntryFingerprinte
@Override
protected File createValidNonEmptyFile() throws IOException {
final File zipFile = tempFolder.newFile("foo.jar");
final File zipFile = tempDir.resolve("foo.jar").toFile();
overwriteZipFileContents(zipFile, new ZipEntry("lib/Foo.class"));
return zipFile;
}