Skip to content

Commit 57a17cb

Browse files
author
fanshilun
committed
HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part2.
1 parent 6d20de1 commit 57a17cb

File tree

99 files changed

+1587
-1384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1587
-1384
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.apache.hadoop.fs.Options.CreateOpts.BlockSize;
2727
import org.apache.hadoop.io.IOUtils;
2828
import org.apache.hadoop.test.GenericTestUtils;
29-
import org.junit.Assert;
29+
import org.junit.jupiter.api.Assertions;
3030

3131
/**
3232
* Helper class for unit tests.
@@ -220,28 +220,28 @@ public enum fileType {isDir, isFile, isSymlink};
220220
public static void checkFileStatus(FileContext aFc, String path,
221221
fileType expectedType) throws IOException {
222222
FileStatus s = aFc.getFileStatus(new Path(path));
223-
Assert.assertNotNull(s);
223+
Assertions.assertNotNull(s);
224224
if (expectedType == fileType.isDir) {
225-
Assert.assertTrue(s.isDirectory());
225+
Assertions.assertTrue(s.isDirectory());
226226
} else if (expectedType == fileType.isFile) {
227-
Assert.assertTrue(s.isFile());
227+
Assertions.assertTrue(s.isFile());
228228
} else if (expectedType == fileType.isSymlink) {
229-
Assert.assertTrue(s.isSymlink());
229+
Assertions.assertTrue(s.isSymlink());
230230
}
231-
Assert.assertEquals(aFc.makeQualified(new Path(path)), s.getPath());
231+
Assertions.assertEquals(aFc.makeQualified(new Path(path)), s.getPath());
232232
}
233233

234234
public static void checkFileLinkStatus(FileContext aFc, String path,
235235
fileType expectedType) throws IOException {
236236
FileStatus s = aFc.getFileLinkStatus(new Path(path));
237-
Assert.assertNotNull(s);
237+
Assertions.assertNotNull(s);
238238
if (expectedType == fileType.isDir) {
239-
Assert.assertTrue(s.isDirectory());
239+
Assertions.assertTrue(s.isDirectory());
240240
} else if (expectedType == fileType.isFile) {
241-
Assert.assertTrue(s.isFile());
241+
Assertions.assertTrue(s.isFile());
242242
} else if (expectedType == fileType.isSymlink) {
243-
Assert.assertTrue(s.isSymlink());
243+
Assertions.assertTrue(s.isSymlink());
244244
}
245-
Assert.assertEquals(aFc.makeQualified(new Path(path)), s.getPath());
245+
Assertions.assertEquals(aFc.makeQualified(new Path(path)), s.getPath());
246246
}
247247
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.apache.hadoop.fs.permission.FsPermission;
2929
import org.apache.hadoop.io.IOUtils;
3030
import org.apache.hadoop.security.AccessControlException;
31-
import org.junit.Assert;
31+
import org.junit.jupiter.api.Assertions;
3232

3333
/**
3434
* Helper class for unit tests.
@@ -169,29 +169,29 @@ public FileStatus containsPath(String path, FileStatus[] dirList)
169169
public void checkFileStatus(String path, fileType expectedType)
170170
throws IOException {
171171
FileStatus s = fc.getFileStatus(new Path(path));
172-
Assert.assertNotNull(s);
172+
Assertions.assertNotNull(s);
173173
if (expectedType == fileType.isDir) {
174-
Assert.assertTrue(s.isDirectory());
174+
Assertions.assertTrue(s.isDirectory());
175175
} else if (expectedType == fileType.isFile) {
176-
Assert.assertTrue(s.isFile());
176+
Assertions.assertTrue(s.isFile());
177177
} else if (expectedType == fileType.isSymlink) {
178-
Assert.assertTrue(s.isSymlink());
178+
Assertions.assertTrue(s.isSymlink());
179179
}
180-
Assert.assertEquals(fc.makeQualified(new Path(path)), s.getPath());
180+
Assertions.assertEquals(fc.makeQualified(new Path(path)), s.getPath());
181181
}
182182

183183
public void checkFileLinkStatus(String path, fileType expectedType)
184184
throws IOException {
185185
FileStatus s = fc.getFileLinkStatus(new Path(path));
186-
Assert.assertNotNull(s);
186+
Assertions.assertNotNull(s);
187187
if (expectedType == fileType.isDir) {
188-
Assert.assertTrue(s.isDirectory());
188+
Assertions.assertTrue(s.isDirectory());
189189
} else if (expectedType == fileType.isFile) {
190-
Assert.assertTrue(s.isFile());
190+
Assertions.assertTrue(s.isFile());
191191
} else if (expectedType == fileType.isSymlink) {
192-
Assert.assertTrue(s.isSymlink());
192+
Assertions.assertTrue(s.isSymlink());
193193
}
194-
Assert.assertEquals(fc.makeQualified(new Path(path)), s.getPath());
194+
Assertions.assertEquals(fc.makeQualified(new Path(path)), s.getPath());
195195
}
196196

197197
//

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import org.apache.hadoop.conf.Configuration;
2626
import org.apache.hadoop.security.token.Token;
2727
import org.apache.hadoop.test.GenericTestUtils;
28-
import org.junit.Assert;
28+
import org.junit.jupiter.api.Assertions;
2929

30-
import static org.junit.Assert.*;
30+
import static org.junit.jupiter.api.Assertions.*;
3131
import static org.mockito.Mockito.mock;
3232

3333
/**
@@ -241,15 +241,15 @@ public enum fileType {isDir, isFile, isSymlink};
241241
public static void checkFileStatus(FileSystem aFs, String path,
242242
fileType expectedType) throws IOException {
243243
FileStatus s = aFs.getFileStatus(new Path(path));
244-
Assert.assertNotNull(s);
244+
Assertions.assertNotNull(s);
245245
if (expectedType == fileType.isDir) {
246-
Assert.assertTrue(s.isDirectory());
246+
Assertions.assertTrue(s.isDirectory());
247247
} else if (expectedType == fileType.isFile) {
248-
Assert.assertTrue(s.isFile());
248+
Assertions.assertTrue(s.isFile());
249249
} else if (expectedType == fileType.isSymlink) {
250-
Assert.assertTrue(s.isSymlink());
250+
Assertions.assertTrue(s.isSymlink());
251251
}
252-
Assert.assertEquals(aFs.makeQualified(new Path(path)), s.getPath());
252+
Assertions.assertEquals(aFs.makeQualified(new Path(path)), s.getPath());
253253
}
254254

255255
/**

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.apache.hadoop.io.IOUtils;
3030
import org.apache.hadoop.security.AccessControlException;
3131
import org.apache.hadoop.util.Progressable;
32-
import org.junit.Assert;
32+
import org.junit.jupiter.api.Assertions;
3333

3434
/**
3535
* Helper class for unit tests.
@@ -170,29 +170,29 @@ public FileStatus containsPath(String path, FileStatus[] dirList)
170170
public void checkFileStatus(String path, fileType expectedType)
171171
throws IOException {
172172
FileStatus s = fs.getFileStatus(new Path(path));
173-
Assert.assertNotNull(s);
173+
Assertions.assertNotNull(s);
174174
if (expectedType == fileType.isDir) {
175-
Assert.assertTrue(s.isDirectory());
175+
Assertions.assertTrue(s.isDirectory());
176176
} else if (expectedType == fileType.isFile) {
177-
Assert.assertTrue(s.isFile());
177+
Assertions.assertTrue(s.isFile());
178178
} else if (expectedType == fileType.isSymlink) {
179-
Assert.assertTrue(s.isSymlink());
179+
Assertions.assertTrue(s.isSymlink());
180180
}
181-
Assert.assertEquals(fs.makeQualified(new Path(path)), s.getPath());
181+
Assertions.assertEquals(fs.makeQualified(new Path(path)), s.getPath());
182182
}
183183

184184
public void checkFileLinkStatus(String path, fileType expectedType)
185185
throws IOException {
186186
FileStatus s = fs.getFileLinkStatus(new Path(path));
187-
Assert.assertNotNull(s);
187+
Assertions.assertNotNull(s);
188188
if (expectedType == fileType.isDir) {
189-
Assert.assertTrue(s.isDirectory());
189+
Assertions.assertTrue(s.isDirectory());
190190
} else if (expectedType == fileType.isFile) {
191-
Assert.assertTrue(s.isFile());
191+
Assertions.assertTrue(s.isFile());
192192
} else if (expectedType == fileType.isSymlink) {
193-
Assert.assertTrue(s.isSymlink());
193+
Assertions.assertTrue(s.isSymlink());
194194
}
195-
Assert.assertEquals(fs.makeQualified(new Path(path)), s.getPath());
195+
Assertions.assertEquals(fs.makeQualified(new Path(path)), s.getPath());
196196
}
197197

198198
//

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import org.apache.hadoop.fs.Options.ChecksumOpt;
2828
import org.apache.hadoop.security.AccessControlException;
2929
import org.apache.hadoop.util.Progressable;
30-
import org.junit.Test;
30+
import org.junit.jupiter.api.Test;
31+
32+
import static org.junit.jupiter.api.Assertions.assertThrows;
3133

3234
public class TestAfsCheckPath {
3335

@@ -56,11 +58,13 @@ public void testCheckPathWithTheSameNonDefaultPort()
5658
afs.checkPath(new Path("dummy://dummy-host:" + OTHER_PORT));
5759
}
5860

59-
@Test(expected=InvalidPathException.class)
61+
@Test
6062
public void testCheckPathWithDifferentPorts() throws URISyntaxException {
61-
URI uri = new URI("dummy://dummy-host:" + DEFAULT_PORT);
62-
AbstractFileSystem afs = new DummyFileSystem(uri);
63-
afs.checkPath(new Path("dummy://dummy-host:" + OTHER_PORT));
63+
assertThrows(InvalidPathException.class, () -> {
64+
URI uri = new URI("dummy://dummy-host:" + DEFAULT_PORT);
65+
AbstractFileSystem afs = new DummyFileSystem(uri);
66+
afs.checkPath(new Path("dummy://dummy-host:" + OTHER_PORT));
67+
});
6468
}
6569

6670
private static class DummyFileSystem extends AbstractFileSystem {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import org.apache.hadoop.conf.Configuration;
2525
import org.apache.hadoop.test.GenericTestUtils;
2626

27-
import org.junit.Test;
28-
import static org.junit.Assert.*;
27+
import org.junit.jupiter.api.Test;
28+
import static org.junit.jupiter.api.Assertions.*;
2929

3030
public class TestAvroFSInput {
3131

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

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

20-
import static org.junit.Assert.assertArrayEquals;
21-
import static org.junit.Assert.assertEquals;
22-
import static org.junit.Assert.assertNotNull;
20+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2323

24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.Timeout;
2526

2627
public class TestBlockLocation {
2728

@@ -70,7 +71,8 @@ private static void checkBlockLocation(final BlockLocation loc,
7071
/**
7172
* Call all the constructors and verify the delegation is working properly
7273
*/
73-
@Test(timeout = 5000)
74+
@Test
75+
@Timeout(value = 5)
7476
public void testBlockLocationConstructors() throws Exception {
7577
//
7678
BlockLocation loc;
@@ -91,7 +93,8 @@ public void testBlockLocationConstructors() throws Exception {
9193
/**
9294
* Call each of the setters and verify
9395
*/
94-
@Test(timeout = 5000)
96+
@Test
97+
@Timeout(value = 5)
9598
public void testBlockLocationSetters() throws Exception {
9699
BlockLocation loc;
97100
loc = new BlockLocation();

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@
2626
import static org.apache.hadoop.fs.FileSystemTestHelper.*;
2727
import org.apache.hadoop.conf.Configuration;
2828
import org.apache.hadoop.test.GenericTestUtils;
29-
import org.junit.*;
30-
import static org.junit.Assert.*;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
31+
32+
import static org.junit.jupiter.api.Assertions.*;
3133

3234
public class TestChecksumFileSystem {
3335
static final String TEST_ROOT_DIR =
3436
GenericTestUtils.getTempPath("work-dir/localfs");
3537

3638
static LocalFileSystem localFs;
3739

38-
@Before
40+
@BeforeEach
3941
public void resetLocalFs() throws Exception {
4042
localFs = FileSystem.getLocal(new Configuration());
4143
localFs.setVerifyChecksum(true);
@@ -77,25 +79,25 @@ public void testVerifyChecksum() throws Exception {
7779
readFile(localFs, testPath, 1025);
7880

7981
localFs.delete(localFs.getChecksumFile(testPath), true);
80-
assertTrue("checksum deleted", !localFs.exists(localFs.getChecksumFile(testPath)));
82+
assertTrue(!localFs.exists(localFs.getChecksumFile(testPath)), "checksum deleted");
8183

8284
//copying the wrong checksum file
8385
FileUtil.copy(localFs, localFs.getChecksumFile(testPath11), localFs,
8486
localFs.getChecksumFile(testPath),false,true,localFs.getConf());
85-
assertTrue("checksum exists", localFs.exists(localFs.getChecksumFile(testPath)));
87+
assertTrue(localFs.exists(localFs.getChecksumFile(testPath)), "checksum exists");
8688

8789
boolean errorRead = false;
8890
try {
8991
readFile(localFs, testPath, 1024);
9092
}catch(ChecksumException ie) {
9193
errorRead = true;
9294
}
93-
assertTrue("error reading", errorRead);
95+
assertTrue(errorRead, "error reading");
9496

9597
//now setting verify false, the read should succeed
9698
localFs.setVerifyChecksum(false);
9799
String str = readFile(localFs, testPath, 1024).toString();
98-
assertTrue("read", "testing".equals(str));
100+
assertTrue("testing".equals(str), "read");
99101
}
100102

101103
@Test
@@ -153,7 +155,7 @@ public void testTruncatedChecksum() throws Exception {
153155
// telling it not to verify checksums, should avoid issue.
154156
localFs.setVerifyChecksum(false);
155157
String str = readFile(localFs, testPath, 1024).toString();
156-
assertTrue("read", "testing truncation".equals(str));
158+
assertTrue("testing truncation".equals(str), "read");
157159
}
158160

159161
@Test
@@ -164,13 +166,13 @@ public void testStreamType() throws Exception {
164166

165167
localFs.setVerifyChecksum(true);
166168
in = localFs.open(testPath);
167-
assertTrue("stream is input checker",
168-
in.getWrappedStream() instanceof FSInputChecker);
169+
assertTrue(
170+
in.getWrappedStream() instanceof FSInputChecker, "stream is input checker");
169171

170172
localFs.setVerifyChecksum(false);
171173
in = localFs.open(testPath);
172-
assertFalse("stream is not input checker",
173-
in.getWrappedStream() instanceof FSInputChecker);
174+
assertFalse(
175+
in.getWrappedStream() instanceof FSInputChecker, "stream is not input checker");
174176
}
175177

176178
@Test
@@ -200,7 +202,7 @@ public void testCorruptedChecksum() throws Exception {
200202
} catch (ChecksumException ce) {
201203
e = ce;
202204
} finally {
203-
assertNotNull("got checksum error", e);
205+
assertNotNull(e, "got checksum error");
204206
}
205207

206208
localFs.setVerifyChecksum(false);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.hadoop.fs;
1919

2020

21-
import static org.junit.Assert.*;
21+
import static org.junit.jupiter.api.Assertions.*;
2222

2323
import java.util.ArrayList;
2424
import java.util.Arrays;
@@ -30,8 +30,8 @@
3030
import org.apache.hadoop.fs.shell.CommandFormat.NotEnoughArgumentsException;
3131
import org.apache.hadoop.fs.shell.CommandFormat.TooManyArgumentsException;
3232
import org.apache.hadoop.fs.shell.CommandFormat.UnknownOptionException;
33-
import org.junit.Before;
34-
import org.junit.Test;
33+
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.Test;
3535

3636
/**
3737
* This class tests the command line parsing
@@ -41,7 +41,7 @@ public class TestCommandFormat {
4141
private static List<String> expectedArgs;
4242
private static Set<String> expectedOpts;
4343

44-
@Before
44+
@BeforeEach
4545
public void setUp() {
4646
args = new ArrayList<>();
4747
expectedOpts = new HashSet<>();

0 commit comments

Comments
 (0)