Browse Source

HADOOP-19550. Migrate ViewFileSystemBaseTest to Junit 5

Closes #7646

Signed-off-by: Chris Nauroth <cnauroth@apache.org>
Istvan Toth 1 month ago
parent
commit
356fd6aea3

+ 15 - 13
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLocalFileSystem.java

@@ -18,10 +18,6 @@
 package org.apache.hadoop.fs.viewfs;
 
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 import java.io.IOException;
 import java.net.URI;
 
@@ -32,11 +28,17 @@ import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import static org.apache.hadoop.fs.FileSystem.TRASH_PREFIX;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
 import org.apache.hadoop.security.UserGroupInformation;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -54,7 +56,7 @@ public class TestViewFileSystemLocalFileSystem extends ViewFileSystemBaseTest {
       LoggerFactory.getLogger(TestViewFileSystemLocalFileSystem.class);
 
   @Override
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     // create the test root on local_fs
     fsTarget = FileSystem.getLocal(new Configuration());
@@ -96,10 +98,10 @@ public class TestViewFileSystemLocalFileSystem extends ViewFileSystemBaseTest {
     FileSystem lfs = FileSystem.getLocal(testConf);
     for (final URI testUri : testUris) {
       final Path testFile = new Path(new Path(testUri), testFileName);
-      assertTrue(testFile + " should exist!",  lfs.exists(testFile));
+      assertTrue(lfs.exists(testFile), testFile + " should exist!");
       final FSDataInputStream fsdis = lfs.open(testFile);
       try {
-        assertEquals("Wrong file content", testString, fsdis.readUTF());
+        assertEquals(fsdis.readUTF(), testString, "Wrong file content");
       } finally {
         fsdis.close();
       }
@@ -122,14 +124,14 @@ public class TestViewFileSystemLocalFileSystem extends ViewFileSystemBaseTest {
       FileSystem.get(URI.create("viewfs://mt/"), conf);
       fail("Expected bad minReplication exception.");
     } catch (IOException ioe) {
-      assertTrue("No minReplication message",
-          ioe.getMessage().contains("Minimum replication"));
+      assertTrue(ioe.getMessage().contains("Minimum replication"),
+          "No minReplication message");
     }
   }
 
 
   @Override
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     fsTarget.delete(fileSystemTestHelper.getTestRootPath(fsTarget), true);
     super.tearDown();

+ 17 - 17
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemWithAuthorityLocalFileSystem.java

@@ -26,12 +26,13 @@ import org.apache.hadoop.fs.FsConstants;
 import org.apache.hadoop.fs.Path;
 import static org.apache.hadoop.fs.FileSystem.TRASH_PREFIX;
 import org.apache.hadoop.security.UserGroupInformation;
+
 import java.io.IOException;
 
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 /**
  * 
@@ -45,7 +46,7 @@ public class TestViewFileSystemWithAuthorityLocalFileSystem extends ViewFileSyst
   URI schemeWithAuthority;
 
   @Override
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     // create the test root on local_fs
     fsTarget = FileSystem.getLocal(new Configuration());
@@ -59,7 +60,7 @@ public class TestViewFileSystemWithAuthorityLocalFileSystem extends ViewFileSyst
   }
 
   @Override
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     fsTarget.delete(fileSystemTestHelper.getTestRootPath(fsTarget), true);
     super.tearDown();
@@ -75,16 +76,15 @@ public class TestViewFileSystemWithAuthorityLocalFileSystem extends ViewFileSyst
   @Override
   @Test
   public void testBasicPaths() {
-    Assert.assertEquals(schemeWithAuthority,
-        fsView.getUri());
-    Assert.assertEquals(fsView.makeQualified(
-        new Path("/user/" + System.getProperty("user.name"))),
-        fsView.getWorkingDirectory());
-    Assert.assertEquals(fsView.makeQualified(
-        new Path("/user/" + System.getProperty("user.name"))),
-        fsView.getHomeDirectory());
-    Assert.assertEquals(
-        new Path("/foo/bar").makeQualified(schemeWithAuthority, null),
-        fsView.makeQualified(new Path("/foo/bar")));
+    Assertions.assertEquals(fsView.getUri(), schemeWithAuthority);
+    Assertions.assertEquals(fsView.getWorkingDirectory(),
+        fsView.makeQualified(
+        new Path("/user/" + System.getProperty("user.name"))));
+    Assertions.assertEquals(fsView.getHomeDirectory(),
+        fsView.makeQualified(
+        new Path("/user/" + System.getProperty("user.name"))));
+    Assertions.assertEquals(
+        fsView.makeQualified(new Path("/foo/bar")),
+        new Path("/foo/bar").makeQualified(schemeWithAuthority, null));
   }
 }

File diff suppressed because it is too large
+ 329 - 295
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java


Some files were not shown because too many files changed in this diff