浏览代码

HADOOP-19547. Migrate FileContextPermissionBase to Junit 5 (#7630) Contributed by Istvan Toth.

Signed-off-by: Shilun Fan <slfan1989@apache.org>
Istvan Toth 2 周之前
父节点
当前提交
7c4e8a2189

+ 15 - 16
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextPermissionBase.java

@@ -24,21 +24,20 @@ import java.util.List;
 import java.util.StringTokenizer;
 import java.util.StringTokenizer;
 
 
 import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.test.GenericTestUtils;
-import org.junit.Assert;
-
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.apache.hadoop.fs.permission.FsPermission;
 import org.apache.hadoop.fs.permission.FsPermission;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.util.Shell;
 import org.apache.hadoop.util.Shell;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.util.StringUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
 import org.slf4j.event.Level;
 import org.slf4j.event.Level;
 
 
 import static org.apache.hadoop.fs.FileContextTestHelper.*;
 import static org.apache.hadoop.fs.FileContextTestHelper.*;
 import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
 import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
 
 /**
 /**
  * <p>
  * <p>
@@ -52,7 +51,7 @@ import static org.junit.Assert.fail;
  * test and override {@link #setUp()} to initialize the <code>fc</code> 
  * test and override {@link #setUp()} to initialize the <code>fc</code> 
  * {@link FileContext} instance variable.
  * {@link FileContext} instance variable.
  * 
  * 
- * Since this a junit 4 you can also do a single setup before 
+ * Since this a junit 4+ you can also do a single setup before
  * the start of any tests.
  * the start of any tests.
  * E.g.
  * E.g.
  *     @BeforeClass   public static void clusterSetupAtBegining()
  *     @BeforeClass   public static void clusterSetupAtBegining()
@@ -80,22 +79,22 @@ public abstract class FileContextPermissionBase {
   
   
   protected abstract FileContext getFileContext() throws Exception;
   protected abstract FileContext getFileContext() throws Exception;
   
   
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
   public void setUp() throws Exception {
     fileContextTestHelper = getFileContextHelper();
     fileContextTestHelper = getFileContextHelper();
     fc = getFileContext();
     fc = getFileContext();
     fc.mkdir(fileContextTestHelper.getTestRootPath(fc), FileContext.DEFAULT_PERM, true);
     fc.mkdir(fileContextTestHelper.getTestRootPath(fc), FileContext.DEFAULT_PERM, true);
   }
   }
 
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
   public void tearDown() throws Exception {
     fc.delete(fileContextTestHelper.getTestRootPath(fc), true);
     fc.delete(fileContextTestHelper.getTestRootPath(fc), true);
   }
   }
   
   
   private void cleanupFile(FileContext fc, Path name) throws IOException {
   private void cleanupFile(FileContext fc, Path name) throws IOException {
-    Assert.assertTrue(exists(fc, name));
+    assertTrue(exists(fc, name));
     fc.delete(name, true);
     fc.delete(name, true);
-    Assert.assertTrue(!exists(fc, name));
+    assertTrue(!exists(fc, name));
   }
   }
 
 
   @Test
   @Test
@@ -158,12 +157,12 @@ public abstract class FileContextPermissionBase {
     try {
     try {
       String g0 = groups.get(0);
       String g0 = groups.get(0);
       fc.setOwner(f, null, g0);
       fc.setOwner(f, null, g0);
-      Assert.assertEquals(g0, fc.getFileStatus(f).getGroup());
+      assertEquals(fc.getFileStatus(f).getGroup(), g0);
 
 
       if (groups.size() > 1) {
       if (groups.size() > 1) {
         String g1 = groups.get(1);
         String g1 = groups.get(1);
         fc.setOwner(f, null, g1);
         fc.setOwner(f, null, g1);
-        Assert.assertEquals(g1, fc.getFileStatus(f).getGroup());
+        assertEquals(fc.getFileStatus(f).getGroup(), g1);
       } else {
       } else {
         System.out.println("Not testing changing the group since user " +
         System.out.println("Not testing changing the group since user " +
                            "belongs to only one group.");
                            "belongs to only one group.");
@@ -193,7 +192,7 @@ public abstract class FileContextPermissionBase {
       }
       }
       
       
     });
     });
-    assertEquals("otherUser",newFc.getUgi().getUserName());
+    assertEquals(newFc.getUgi().getUserName(), "otherUser");
   }
   }
 
 
   static List<String> getGroups() throws IOException {
   static List<String> getGroups() throws IOException {
@@ -207,7 +206,7 @@ public abstract class FileContextPermissionBase {
   
   
   
   
   void doFilePermissionCheck(FsPermission expectedPerm, FsPermission actualPerm) {
   void doFilePermissionCheck(FsPermission expectedPerm, FsPermission actualPerm) {
-  Assert.assertEquals(expectedPerm.applyUMask(getFileMask()), actualPerm);
+    assertEquals(expectedPerm.applyUMask(getFileMask()), actualPerm);
   }
   }
   
   
   
   

+ 4 - 4
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFcLocalFsPermission.java

@@ -17,8 +17,8 @@
  */
  */
 package org.apache.hadoop.fs;
 package org.apache.hadoop.fs;
 
 
-import org.junit.After;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 
 
 /**
 /**
  * Test permissions for localFs using FileContext API.
  * Test permissions for localFs using FileContext API.
@@ -27,13 +27,13 @@ public class TestFcLocalFsPermission extends
   FileContextPermissionBase {
   FileContextPermissionBase {
 
 
   @Override
   @Override
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
   public void setUp() throws Exception {
     super.setUp();
     super.setUp();
   }
   }
 
 
   @Override
   @Override
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
   public void tearDown() throws Exception {
     super.tearDown();
     super.tearDown();
   }
   }

+ 4 - 4
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcPermissionsLocalFs.java

@@ -20,21 +20,21 @@ package org.apache.hadoop.fs.viewfs;
 
 
 import org.apache.hadoop.fs.FileContext;
 import org.apache.hadoop.fs.FileContext;
 import org.apache.hadoop.fs.FileContextPermissionBase;
 import org.apache.hadoop.fs.FileContextPermissionBase;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 
 
-import org.junit.After;
-import org.junit.Before;
 
 
 
 
 public class TestFcPermissionsLocalFs  extends FileContextPermissionBase {
 public class TestFcPermissionsLocalFs  extends FileContextPermissionBase {
 
 
   @Override
   @Override
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
   public void setUp() throws Exception {
     super.setUp();
     super.setUp();
   }
   }
   
   
   @Override
   @Override
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
   public void tearDown() throws Exception {
     super.tearDown();
     super.tearDown();
     ViewFsTestSetup.tearDownForViewFsLocalFs(fileContextTestHelper);
     ViewFsTestSetup.tearDownForViewFsLocalFs(fileContextTestHelper);