This is an automated email from the ASF dual-hosted git repository. slfan1989 pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push: new 7c4e8a21896 HADOOP-19547. Migrate FileContextPermissionBase to Junit 5 (#7630) Contributed by Istvan Toth. 7c4e8a21896 is described below commit 7c4e8a2189624679ffcdce0127d21de98ebcd3a1 Author: Istvan Toth <st...@apache.org> AuthorDate: Fri Apr 18 01:35:24 2025 +0200 HADOOP-19547. Migrate FileContextPermissionBase to Junit 5 (#7630) Contributed by Istvan Toth. Signed-off-by: Shilun Fan <slfan1...@apache.org> --- .../hadoop/fs/FileContextPermissionBase.java | 31 +++++++++++----------- .../apache/hadoop/fs/TestFcLocalFsPermission.java | 8 +++--- .../hadoop/fs/viewfs/TestFcPermissionsLocalFs.java | 8 +++--- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextPermissionBase.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextPermissionBase.java index 240989eea58..713de5c72ca 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextPermissionBase.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextPermissionBase.java @@ -24,21 +24,20 @@ import java.util.StringTokenizer; 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.security.UserGroupInformation; import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.StringUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; import org.slf4j.event.Level; import static org.apache.hadoop.fs.FileContextTestHelper.*; 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> @@ -52,7 +51,7 @@ * test and override {@link #setUp()} to initialize the <code>fc</code> * {@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. * E.g. * @BeforeClass public static void clusterSetupAtBegining() @@ -80,22 +79,22 @@ protected FileContextTestHelper getFileContextHelper() { protected abstract FileContext getFileContext() throws Exception; - @Before + @BeforeEach public void setUp() throws Exception { fileContextTestHelper = getFileContextHelper(); fc = getFileContext(); fc.mkdir(fileContextTestHelper.getTestRootPath(fc), FileContext.DEFAULT_PERM, true); } - @After + @AfterEach public void tearDown() throws Exception { fc.delete(fileContextTestHelper.getTestRootPath(fc), true); } private void cleanupFile(FileContext fc, Path name) throws IOException { - Assert.assertTrue(exists(fc, name)); + assertTrue(exists(fc, name)); fc.delete(name, true); - Assert.assertTrue(!exists(fc, name)); + assertTrue(!exists(fc, name)); } @Test @@ -158,12 +157,12 @@ public void testSetOwner() throws IOException { try { String g0 = groups.get(0); fc.setOwner(f, null, g0); - Assert.assertEquals(g0, fc.getFileStatus(f).getGroup()); + assertEquals(fc.getFileStatus(f).getGroup(), g0); if (groups.size() > 1) { String g1 = groups.get(1); fc.setOwner(f, null, g1); - Assert.assertEquals(g1, fc.getFileStatus(f).getGroup()); + assertEquals(fc.getFileStatus(f).getGroup(), g1); } else { System.out.println("Not testing changing the group since user " + "belongs to only one group."); @@ -193,7 +192,7 @@ public FileContext run() throws Exception { } }); - assertEquals("otherUser",newFc.getUgi().getUserName()); + assertEquals(newFc.getUgi().getUserName(), "otherUser"); } static List<String> getGroups() throws IOException { @@ -207,7 +206,7 @@ static List<String> getGroups() throws IOException { void doFilePermissionCheck(FsPermission expectedPerm, FsPermission actualPerm) { - Assert.assertEquals(expectedPerm.applyUMask(getFileMask()), actualPerm); + assertEquals(expectedPerm.applyUMask(getFileMask()), actualPerm); } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFcLocalFsPermission.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFcLocalFsPermission.java index 848eeb01961..3534e3b1c3a 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFcLocalFsPermission.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFcLocalFsPermission.java @@ -17,8 +17,8 @@ */ 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. @@ -27,13 +27,13 @@ public class TestFcLocalFsPermission extends FileContextPermissionBase { @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); } @Override - @After + @AfterEach public void tearDown() throws Exception { super.tearDown(); } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcPermissionsLocalFs.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcPermissionsLocalFs.java index afbbd635e9f..226632024b5 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcPermissionsLocalFs.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcPermissionsLocalFs.java @@ -20,21 +20,21 @@ import org.apache.hadoop.fs.FileContext; 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 { @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); } @Override - @After + @AfterEach public void tearDown() throws Exception { super.tearDown(); ViewFsTestSetup.tearDownForViewFsLocalFs(fileContextTestHelper); --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org