Upgrade from Junit4 to Junit5
diff --git a/modules/vfs-class-loader/pom.xml b/modules/vfs-class-loader/pom.xml
index 15865b8..1ebcc44 100644
--- a/modules/vfs-class-loader/pom.xml
+++ b/modules/vfs-class-loader/pom.xml
@@ -89,11 +89,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client-minicluster</artifactId>
<scope>test</scope>
@@ -110,6 +105,11 @@
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<pluginManagement>
diff --git a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/AccumuloDFSBase.java b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/AccumuloDFSBase.java
index c8a63e8..294c354 100644
--- a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/AccumuloDFSBase.java
+++ b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/AccumuloDFSBase.java
@@ -35,8 +35,8 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.MiniDFSCluster;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -80,7 +80,7 @@
}
}
- @BeforeClass
+ @BeforeAll
public static void miniDfsClusterSetup() {
System.setProperty("java.io.tmpdir", System.getProperty("user.dir") + "/target");
@@ -164,7 +164,7 @@
return vfs;
}
- @AfterClass
+ @AfterAll
public static void tearDownMiniDfsCluster() {
if (null != cluster) {
cluster.shutdown();
diff --git a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/AccumuloVFSClassLoaderTest.java b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/AccumuloVFSClassLoaderTest.java
index e86b296..5b63a7b 100644
--- a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/AccumuloVFSClassLoaderTest.java
+++ b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/AccumuloVFSClassLoaderTest.java
@@ -18,37 +18,36 @@
*/
package org.apache.accumulo.classloader.vfs;
-import static org.junit.Assert.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import java.io.File;
+import java.util.Objects;
import org.apache.commons.io.FileUtils;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not set by user input")
public class AccumuloVFSClassLoaderTest {
- @Rule
- public TemporaryFolder folder1 =
- new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+ @TempDir
+ private static File tempDir;
String folderPath;
- @Before
+ @BeforeEach
public void setup() throws Exception {
System.setProperty(AccumuloVFSClassLoader.VFS_CLASSPATH_MONITOR_INTERVAL, "1");
VFSManager.initialize();
- folderPath = folder1.getRoot().toURI() + ".*";
+ folderPath = tempDir.toURI() + ".*";
- FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"),
- folder1.newFile("HelloWorld.jar"));
+ FileUtils.copyURLToFile(Objects.requireNonNull(this.getClass().getResource("/HelloWorld.jar")),
+ new File(tempDir, "HelloWorld.jar"));
}
FileObject[] createFileSystems(FileObject[] fos) throws FileSystemException {
@@ -66,7 +65,7 @@
@Test
public void testConstructor() throws Exception {
- FileObject testDir = VFSManager.get().resolveFile(folder1.getRoot().toURI().toString());
+ FileObject testDir = VFSManager.get().resolveFile(tempDir.toURI().toString());
FileObject[] dirContents = testDir.getChildren();
AccumuloVFSClassLoader arvcl = new AccumuloVFSClassLoader(ClassLoader.getSystemClassLoader()) {
diff --git a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/ClassPathPrinterTest.java b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/ClassPathPrinterTest.java
index aa063bc..baf019b 100644
--- a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/ClassPathPrinterTest.java
+++ b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/ClassPathPrinterTest.java
@@ -18,40 +18,39 @@
*/
package org.apache.accumulo.classloader.vfs;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.net.MalformedURLException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not set by user input")
public class ClassPathPrinterTest {
- @Rule
- public TemporaryFolder folder1 =
- new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+ @TempDir
+ private static File tempDir;
private final ClassLoader parent = ClassPathPrinterTest.class.getClassLoader();
private static void assertPattern(String output, String pattern, boolean shouldMatch) {
if (shouldMatch) {
- assertTrue("Pattern " + pattern + " did not match output: " + output,
- output.matches(pattern));
+ assertTrue(output.matches(pattern),
+ "Pattern " + pattern + " did not match output: " + output);
} else {
- assertFalse("Pattern " + pattern + " should not match output: " + output,
- output.matches(pattern));
+ assertFalse(output.matches(pattern),
+ "Pattern " + pattern + " should not match output: " + output);
}
}
@Test
public void testPrintClassPath() throws Exception {
- File conf = folder1.newFile("accumulo.properties");
+ File conf = new File(tempDir, "accumulo.properties");
+ assertTrue(conf.isFile() || conf.createNewFile());
VFSManager.initialize();
AccumuloVFSClassLoader cl = new AccumuloVFSClassLoader(parent) {
diff --git a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/VfsClassLoaderTest.java b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/VfsClassLoaderTest.java
index e5a5cd1..a3bbb4e 100644
--- a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/VfsClassLoaderTest.java
+++ b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/VfsClassLoaderTest.java
@@ -18,9 +18,9 @@
*/
package org.apache.accumulo.classloader.vfs;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.net.URL;
import java.util.Arrays;
@@ -34,10 +34,10 @@
import org.apache.commons.vfs2.impl.VFSClassLoader;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,23 +49,23 @@
private static FileSystem hdfs = null;
private static DefaultFileSystemManager vfs = null;
- @BeforeClass
+ @BeforeAll
public static void setup() throws Exception {
// miniDfsClusterSetup();
hdfs = getCluster().getFileSystem();
- assertTrue("Unable to create: " + TEST_DIR, hdfs.mkdirs(TEST_DIR));
+ assertTrue(hdfs.mkdirs(TEST_DIR), "Unable to create: " + TEST_DIR);
vfs = getDefaultFileSystemManager();
}
- @Before
+ @BeforeEach
public void before() throws Exception {
// Copy jar file to TEST_DIR
URL jarPath = VfsClassLoaderTest.class.getResource("/HelloWorld.jar");
- assertNotNull("Unable to find HelloWorld.jar", jarPath);
+ assertNotNull(jarPath, "Unable to find HelloWorld.jar");
Path src = new Path(jarPath.toURI().toString());
Path dst = new Path(TEST_DIR, src.getName());
LOG.info("Copying {} to {}", src, dst);
@@ -76,7 +76,7 @@
public void testGetClass() throws Exception {
FileObject testDir = vfs.resolveFile(TEST_DIR.toUri().toString());
- assertNotNull("Unable to resolve test dir via VFS", testDir);
+ assertNotNull(testDir, "Unable to resolve test dir via VFS");
FileObject[] dirContents = testDir.getChildren();
LOG.info("Test directory contents according to VFS: {}", Arrays.toString(dirContents));
@@ -134,7 +134,7 @@
}
- @AfterClass
+ @AfterAll
public static void tearDown() throws Exception {
hdfs.delete(TEST_DIR, true);
tearDownMiniDfsCluster();
diff --git a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/context/ReloadingVFSContextClassLoaderFactoryTest.java b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/context/ReloadingVFSContextClassLoaderFactoryTest.java
index 4846b3c..0bb9dd2 100644
--- a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/context/ReloadingVFSContextClassLoaderFactoryTest.java
+++ b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/context/ReloadingVFSContextClassLoaderFactoryTest.java
@@ -20,10 +20,10 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardOpenOption.WRITE;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.BufferedWriter;
import java.io.File;
@@ -36,10 +36,10 @@
import org.apache.accumulo.classloader.vfs.context.ReloadingVFSContextClassLoaderFactory.ContextConfig;
import org.apache.accumulo.classloader.vfs.context.ReloadingVFSContextClassLoaderFactory.Contexts;
import org.apache.commons.io.FileUtils;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.io.TempDir;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -96,16 +96,15 @@
}
}
- @Rule
- public TemporaryFolder TEMP =
- new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+ @TempDir
+ private static File tempDir;
private static final Contexts c = new Contexts();
private static File foo = new File(System.getProperty("user.dir") + "/target/foo");
private static File bar = new File(System.getProperty("user.dir") + "/target/bar");
- @BeforeClass
+ @BeforeAll
public static void setup() throws Exception {
assertTrue(foo.mkdir());
@@ -148,14 +147,19 @@
}
@Test
- public void testCreation() throws Exception {
+ public void testCreation(TestInfo testInfo) throws Exception {
FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"),
new File(foo, "HelloWorld.jar"));
FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"),
new File(bar, "HelloWorld2.jar"));
- File f = TEMP.newFile();
+ String testMethodName = testInfo.getTestMethod().get().getName();
+ File testSubDir = new File(tempDir, testMethodName);
+ assertTrue(testSubDir.isDirectory() || testSubDir.mkdir());
+
+ File f = new File(testSubDir, "configFile");
+ assertTrue(f.isFile() || f.createNewFile());
f.deleteOnExit();
Gson g = new Gson();
String contexts = g.toJson(c);
@@ -180,7 +184,7 @@
}
@Test
- public void testReloading() throws Exception {
+ public void testReloading(TestInfo testInfo) throws Exception {
System.setProperty(AccumuloVFSClassLoader.VFS_CLASSPATH_MONITOR_INTERVAL, "1");
@@ -189,7 +193,12 @@
FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"),
new File(bar, "HelloWorld2.jar"));
- File f = TEMP.newFile();
+ String testMethodName = testInfo.getTestMethod().get().getName();
+ File testSubDir = new File(tempDir, testMethodName);
+ assertTrue(testSubDir.isDirectory() || testSubDir.mkdir());
+
+ File f = new File(testSubDir, "configFile");
+ assertTrue(f.isFile() || f.createNewFile());
f.deleteOnExit();
Gson g = new Gson();
String contexts = g.toJson(c);
diff --git a/pom.xml b/pom.xml
index 03d27fd..c584472 100644
--- a/pom.xml
+++ b/pom.xml
@@ -171,12 +171,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.apache.accumulo</groupId>
<artifactId>accumulo-start</artifactId>
<version>2.1.0</version>
@@ -206,6 +200,12 @@
<version>2.19.0</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <version>5.9.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</dependencyManagement>
<build>
@@ -229,6 +229,16 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>3.0.0-M6</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>3.0.0-M6</version>
+ </plugin>
+ <plugin>
<groupId>com.github.ekryd.sortpom</groupId>
<artifactId>sortpom-maven-plugin</artifactId>
<version>2.12.0</version>
@@ -340,11 +350,19 @@
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="junit[.]framework[.]TestCase" />
- <property name="message" value="Use JUnit4+ @Test annotation instead of TestCase" />
+ <property name="message" value="Use JUnit5+ @Test annotation instead of TestCase" />
</module>
<module name="RegexpSinglelineJava">
- <property name="format" value="import org[.]junit[.]Assert;" />
- <property name="message" value="Use static imports for Assert.* methods for consistency" />
+ <property name="format" value="org[.]junit[.](?!jupiter)" />
+ <property name="message" value="Use JUnit5 (JUnit Jupiter) instead of JUnit4 (or lower)" />
+ </module>
+ <module name="RegexpSinglelineJava">
+ <property name="format" value="org[.]junit[.]jupiter[.]api[.]Assertions;" />
+ <property name="message" value="Use static imports for Assertions.* methods for consistency" />
+ </module>
+ <module name="RegexpSinglelineJava">
+ <property name="format" value="org[.]junit[.]jupiter[.]api[.]Assumptions;" />
+ <property name="message" value="Use static imports for Assumptions.* methods for consistency" />
</module>
<module name="OuterTypeFilename" />
<module name="AvoidStarImport" />