Skip to content

Commit 7c4e8a2

Browse files
authored
HADOOP-19547. Migrate FileContextPermissionBase to Junit 5 (#7630) Contributed by Istvan Toth.
Signed-off-by: Shilun Fan <slfan1989@apache.org>
1 parent 263404e commit 7c4e8a2

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,20 @@
2424
import java.util.StringTokenizer;
2525

2626
import org.apache.hadoop.test.GenericTestUtils;
27-
import org.junit.Assert;
28-
27+
import org.junit.jupiter.api.AfterEach;
28+
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.Test;
2930
import org.apache.hadoop.fs.permission.FsPermission;
3031
import org.apache.hadoop.security.UserGroupInformation;
3132
import org.apache.hadoop.util.Shell;
3233
import org.apache.hadoop.util.StringUtils;
33-
import org.junit.After;
34-
import org.junit.Before;
35-
import org.junit.Test;
3634
import org.slf4j.event.Level;
3735

3836
import static org.apache.hadoop.fs.FileContextTestHelper.*;
3937
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
40-
import static org.junit.Assert.assertEquals;
41-
import static org.junit.Assert.fail;
38+
import static org.junit.jupiter.api.Assertions.assertEquals;
39+
import static org.junit.jupiter.api.Assertions.assertTrue;
40+
import static org.junit.jupiter.api.Assertions.fail;
4241

4342
/**
4443
* <p>
@@ -52,7 +51,7 @@
5251
* test and override {@link #setUp()} to initialize the <code>fc</code>
5352
* {@link FileContext} instance variable.
5453
*
55-
* Since this a junit 4 you can also do a single setup before
54+
* Since this a junit 4+ you can also do a single setup before
5655
* the start of any tests.
5756
* E.g.
5857
* @BeforeClass public static void clusterSetupAtBegining()
@@ -80,22 +79,22 @@ protected FileContextTestHelper getFileContextHelper() {
8079

8180
protected abstract FileContext getFileContext() throws Exception;
8281

83-
@Before
82+
@BeforeEach
8483
public void setUp() throws Exception {
8584
fileContextTestHelper = getFileContextHelper();
8685
fc = getFileContext();
8786
fc.mkdir(fileContextTestHelper.getTestRootPath(fc), FileContext.DEFAULT_PERM, true);
8887
}
8988

90-
@After
89+
@AfterEach
9190
public void tearDown() throws Exception {
9291
fc.delete(fileContextTestHelper.getTestRootPath(fc), true);
9392
}
9493

9594
private void cleanupFile(FileContext fc, Path name) throws IOException {
96-
Assert.assertTrue(exists(fc, name));
95+
assertTrue(exists(fc, name));
9796
fc.delete(name, true);
98-
Assert.assertTrue(!exists(fc, name));
97+
assertTrue(!exists(fc, name));
9998
}
10099

101100
@Test
@@ -158,12 +157,12 @@ public void testSetOwner() throws IOException {
158157
try {
159158
String g0 = groups.get(0);
160159
fc.setOwner(f, null, g0);
161-
Assert.assertEquals(g0, fc.getFileStatus(f).getGroup());
160+
assertEquals(fc.getFileStatus(f).getGroup(), g0);
162161

163162
if (groups.size() > 1) {
164163
String g1 = groups.get(1);
165164
fc.setOwner(f, null, g1);
166-
Assert.assertEquals(g1, fc.getFileStatus(f).getGroup());
165+
assertEquals(fc.getFileStatus(f).getGroup(), g1);
167166
} else {
168167
System.out.println("Not testing changing the group since user " +
169168
"belongs to only one group.");
@@ -193,7 +192,7 @@ public FileContext run() throws Exception {
193192
}
194193

195194
});
196-
assertEquals("otherUser",newFc.getUgi().getUserName());
195+
assertEquals(newFc.getUgi().getUserName(), "otherUser");
197196
}
198197

199198
static List<String> getGroups() throws IOException {
@@ -207,7 +206,7 @@ static List<String> getGroups() throws IOException {
207206

208207

209208
void doFilePermissionCheck(FsPermission expectedPerm, FsPermission actualPerm) {
210-
Assert.assertEquals(expectedPerm.applyUMask(getFileMask()), actualPerm);
209+
assertEquals(expectedPerm.applyUMask(getFileMask()), actualPerm);
211210
}
212211

213212

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818
package org.apache.hadoop.fs;
1919

20-
import org.junit.After;
21-
import org.junit.Before;
20+
import org.junit.jupiter.api.AfterEach;
21+
import org.junit.jupiter.api.BeforeEach;
2222

2323
/**
2424
* Test permissions for localFs using FileContext API.
@@ -27,13 +27,13 @@ public class TestFcLocalFsPermission extends
2727
FileContextPermissionBase {
2828

2929
@Override
30-
@Before
30+
@BeforeEach
3131
public void setUp() throws Exception {
3232
super.setUp();
3333
}
3434

3535
@Override
36-
@After
36+
@AfterEach
3737
public void tearDown() throws Exception {
3838
super.tearDown();
3939
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@
2020

2121
import org.apache.hadoop.fs.FileContext;
2222
import org.apache.hadoop.fs.FileContextPermissionBase;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.BeforeEach;
2325

24-
import org.junit.After;
25-
import org.junit.Before;
2626

2727

2828
public class TestFcPermissionsLocalFs extends FileContextPermissionBase {
2929

3030
@Override
31-
@Before
31+
@BeforeEach
3232
public void setUp() throws Exception {
3333
super.setUp();
3434
}
3535

3636
@Override
37-
@After
37+
@AfterEach
3838
public void tearDown() throws Exception {
3939
super.tearDown();
4040
ViewFsTestSetup.tearDownForViewFsLocalFs(fileContextTestHelper);

0 commit comments

Comments
 (0)