Skip to content

Commit 0e69dd3

Browse files
committed
HADOOP-19550. Migrate ViewFileSystemBaseTest to Junit 5
1 parent 6760271 commit 0e69dd3

File tree

3 files changed

+453
-418
lines changed

3 files changed

+453
-418
lines changed

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

+15-13
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
package org.apache.hadoop.fs.viewfs;
1919

2020

21-
import static org.junit.Assert.assertEquals;
22-
import static org.junit.Assert.assertTrue;
23-
import static org.junit.Assert.fail;
24-
2521
import java.io.IOException;
2622
import java.net.URI;
2723

@@ -32,11 +28,17 @@
3228
import org.apache.hadoop.fs.FileSystem;
3329
import org.apache.hadoop.fs.Path;
3430
import static org.apache.hadoop.fs.FileSystem.TRASH_PREFIX;
31+
import static org.junit.jupiter.api.Assertions.assertEquals;
32+
import static org.junit.jupiter.api.Assertions.assertTrue;
33+
import static org.junit.jupiter.api.Assertions.fail;
34+
3535
import org.apache.hadoop.security.UserGroupInformation;
3636

37-
import org.junit.After;
38-
import org.junit.Before;
39-
import org.junit.Test;
37+
import org.junit.jupiter.api.AfterEach;
38+
import org.junit.jupiter.api.BeforeEach;
39+
import org.junit.jupiter.api.Test;
40+
41+
4042
import org.slf4j.Logger;
4143
import org.slf4j.LoggerFactory;
4244

@@ -54,7 +56,7 @@ public class TestViewFileSystemLocalFileSystem extends ViewFileSystemBaseTest {
5456
LoggerFactory.getLogger(TestViewFileSystemLocalFileSystem.class);
5557

5658
@Override
57-
@Before
59+
@BeforeEach
5860
public void setUp() throws Exception {
5961
// create the test root on local_fs
6062
fsTarget = FileSystem.getLocal(new Configuration());
@@ -96,10 +98,10 @@ public void testNflyWriteSimple() throws IOException {
9698
FileSystem lfs = FileSystem.getLocal(testConf);
9799
for (final URI testUri : testUris) {
98100
final Path testFile = new Path(new Path(testUri), testFileName);
99-
assertTrue(testFile + " should exist!", lfs.exists(testFile));
101+
assertTrue(lfs.exists(testFile), testFile + " should exist!");
100102
final FSDataInputStream fsdis = lfs.open(testFile);
101103
try {
102-
assertEquals("Wrong file content", testString, fsdis.readUTF());
104+
assertEquals(fsdis.readUTF(), testString, "Wrong file content");
103105
} finally {
104106
fsdis.close();
105107
}
@@ -122,14 +124,14 @@ public void testNflyInvalidMinReplication() throws Exception {
122124
FileSystem.get(URI.create("viewfs://mt/"), conf);
123125
fail("Expected bad minReplication exception.");
124126
} catch (IOException ioe) {
125-
assertTrue("No minReplication message",
126-
ioe.getMessage().contains("Minimum replication"));
127+
assertTrue(ioe.getMessage().contains("Minimum replication"),
128+
"No minReplication message");
127129
}
128130
}
129131

130132

131133
@Override
132-
@After
134+
@AfterEach
133135
public void tearDown() throws Exception {
134136
fsTarget.delete(fileSystemTestHelper.getTestRootPath(fsTarget), true);
135137
super.tearDown();

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

+17-17
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
import org.apache.hadoop.fs.Path;
2727
import static org.apache.hadoop.fs.FileSystem.TRASH_PREFIX;
2828
import org.apache.hadoop.security.UserGroupInformation;
29+
2930
import java.io.IOException;
3031

31-
import org.junit.After;
32-
import org.junit.Assert;
33-
import org.junit.Before;
34-
import org.junit.Test;
32+
import org.junit.jupiter.api.AfterEach;
33+
import org.junit.jupiter.api.Assertions;
34+
import org.junit.jupiter.api.BeforeEach;
35+
import org.junit.jupiter.api.Test;
3536

3637
/**
3738
*
@@ -45,7 +46,7 @@ public class TestViewFileSystemWithAuthorityLocalFileSystem extends ViewFileSyst
4546
URI schemeWithAuthority;
4647

4748
@Override
48-
@Before
49+
@BeforeEach
4950
public void setUp() throws Exception {
5051
// create the test root on local_fs
5152
fsTarget = FileSystem.getLocal(new Configuration());
@@ -59,7 +60,7 @@ public void setUp() throws Exception {
5960
}
6061

6162
@Override
62-
@After
63+
@AfterEach
6364
public void tearDown() throws Exception {
6465
fsTarget.delete(fileSystemTestHelper.getTestRootPath(fsTarget), true);
6566
super.tearDown();
@@ -75,16 +76,15 @@ Path getTrashRootInFallBackFS() throws IOException {
7576
@Override
7677
@Test
7778
public void testBasicPaths() {
78-
Assert.assertEquals(schemeWithAuthority,
79-
fsView.getUri());
80-
Assert.assertEquals(fsView.makeQualified(
81-
new Path("/user/" + System.getProperty("user.name"))),
82-
fsView.getWorkingDirectory());
83-
Assert.assertEquals(fsView.makeQualified(
84-
new Path("/user/" + System.getProperty("user.name"))),
85-
fsView.getHomeDirectory());
86-
Assert.assertEquals(
87-
new Path("/foo/bar").makeQualified(schemeWithAuthority, null),
88-
fsView.makeQualified(new Path("/foo/bar")));
79+
Assertions.assertEquals(fsView.getUri(), schemeWithAuthority);
80+
Assertions.assertEquals(fsView.getWorkingDirectory(),
81+
fsView.makeQualified(
82+
new Path("/user/" + System.getProperty("user.name"))));
83+
Assertions.assertEquals(fsView.getHomeDirectory(),
84+
fsView.makeQualified(
85+
new Path("/user/" + System.getProperty("user.name"))));
86+
Assertions.assertEquals(
87+
fsView.makeQualified(new Path("/foo/bar")),
88+
new Path("/foo/bar").makeQualified(schemeWithAuthority, null));
8989
}
9090
}

0 commit comments

Comments
 (0)