Skip to content

Commit 94597e3

Browse files
committed
HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part7.
1 parent d1f75ad commit 94597e3

File tree

3 files changed

+94
-94
lines changed

3 files changed

+94
-94
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
import static org.apache.hadoop.fs.FileContextTestHelper.readFile;
2121
import static org.apache.hadoop.fs.FileContextTestHelper.writeFile;
22-
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
import static org.junit.Assert.assertTrue;
2323

2424
import java.util.Arrays;
2525

2626
import org.apache.hadoop.test.GenericTestUtils;
2727
import org.apache.hadoop.util.StringUtils;
28-
import org.junit.jupiter.api.AfterEach;
29-
import org.junit.jupiter.api.BeforeEach;
30-
import org.junit.jupiter.api.Test;
28+
import org.junit.After;
29+
import org.junit.Before;
30+
import org.junit.Test;
3131
import org.slf4j.event.Level;
3232

3333
/**
@@ -57,12 +57,12 @@ public abstract class FileContextUtilBase {
5757
}
5858
}
5959

60-
@BeforeEach
60+
@Before
6161
public void setUp() throws Exception {
6262
fc.mkdir(fileContextTestHelper.getTestRootPath(fc), FileContext.DEFAULT_PERM, true);
6363
}
6464

65-
@AfterEach
65+
@After
6666
public void tearDown() throws Exception {
6767
if (fc != null) {
6868
fc.delete(fileContextTestHelper.getTestRootPath(fc), true);
@@ -80,10 +80,10 @@ public void testFcCopy() throws Exception{
8080
fc.util().copy(file1, file2);
8181

8282
// verify that newly copied file2 exists
83-
assertTrue(fc.util().exists(file2), "Failed to copy file2 ");
83+
assertTrue("Failed to copy file2 ", fc.util().exists(file2));
8484
// verify that file2 contains test string
85-
assertTrue(Arrays.equals(ts.getBytes(),
86-
readFile(fc,file2,ts.getBytes().length)), "Copied files does not match ");
85+
assertTrue("Copied files does not match ",Arrays.equals(ts.getBytes(),
86+
readFile(fc,file2,ts.getBytes().length)));
8787
}
8888

8989
@Test
@@ -103,9 +103,9 @@ public void testRecursiveFcCopy() throws Exception {
103103
fc.util().copy(dir1, dir2);
104104

105105
// verify that newly copied file2 exists
106-
assertTrue(fc.util().exists(file2), "Failed to copy file2 ");
106+
assertTrue("Failed to copy file2 ", fc.util().exists(file2));
107107
// verify that file2 contains test string
108-
assertTrue(Arrays.equals(ts.getBytes(),
109-
readFile(fc,file2,ts.getBytes().length)), "Copied files does not match ");
108+
assertTrue("Copied files does not match ",Arrays.equals(ts.getBytes(),
109+
readFile(fc,file2,ts.getBytes().length)));
110110
}
111111
}

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

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
import org.apache.hadoop.security.AccessControlException;
3232
import org.apache.hadoop.util.StringUtils;
3333

34-
import static org.junit.jupiter.api.Assertions.*;
34+
import static org.junit.Assert.*;
3535
import static org.junit.Assume.assumeTrue;
3636

37-
import org.junit.jupiter.api.AfterEach;
37+
import org.junit.After;
3838
import org.junit.Rule;
39-
import org.junit.jupiter.api.Test;
39+
import org.junit.Test;
4040
import org.junit.rules.Timeout;
4141

4242
/**
@@ -72,7 +72,7 @@ protected int getGlobalTimeout() {
7272
return 30 * 1000;
7373
}
7474

75-
@AfterEach
75+
@After
7676
public void tearDown() throws Exception {
7777
if (fs != null) {
7878
// some cases use this absolute path
@@ -195,7 +195,7 @@ public void testMkdirs() throws Exception {
195195
assertTrue(fs.mkdirs(testDir));
196196

197197
assertTrue(fs.exists(testDir));
198-
assertTrue(fs.isDirectory(testDir), "Should be a directory");
198+
assertTrue("Should be a directory", fs.isDirectory(testDir));
199199
assertFalse(fs.isFile(testDir));
200200

201201
Path parentDir = testDir.getParent();
@@ -365,8 +365,8 @@ public void testOverwrite() throws IOException {
365365

366366
createFile(path);
367367

368-
assertTrue(fs.exists(path), "Exists");
369-
assertEquals(data.length, fs.getFileStatus(path).getLen(), "Length");
368+
assertTrue("Exists", fs.exists(path));
369+
assertEquals("Length", data.length, fs.getFileStatus(path).getLen());
370370

371371
try {
372372
fs.create(path, false).close();
@@ -379,27 +379,27 @@ public void testOverwrite() throws IOException {
379379
out.write(data, 0, data.length);
380380
out.close();
381381

382-
assertTrue(fs.exists(path), "Exists");
383-
assertEquals(data.length, fs.getFileStatus(path).getLen(), "Length");
382+
assertTrue("Exists", fs.exists(path));
383+
assertEquals("Length", data.length, fs.getFileStatus(path).getLen());
384384

385385
}
386386

387387
@Test
388388
public void testWriteInNonExistentDirectory() throws IOException {
389389
Path path = path("testWriteInNonExistentDirectory/file");
390-
assertFalse(fs.exists(path.getParent()), "Parent exists");
390+
assertFalse("Parent exists", fs.exists(path.getParent()));
391391
createFile(path);
392392

393-
assertTrue(fs.exists(path), "Exists");
394-
assertEquals(data.length, fs.getFileStatus(path).getLen(), "Length");
395-
assertTrue(fs.exists(path.getParent()), "Parent exists");
393+
assertTrue("Exists", fs.exists(path));
394+
assertEquals("Length", data.length, fs.getFileStatus(path).getLen());
395+
assertTrue("Parent exists", fs.exists(path.getParent()));
396396
}
397397

398398
@Test
399399
public void testDeleteNonExistentFile() throws IOException {
400400
Path path = path("testDeleteNonExistentFile/file");
401-
assertFalse(fs.exists(path), "Path exists: " + path);
402-
assertFalse(fs.delete(path, true), "No deletion");
401+
assertFalse("Path exists: " + path, fs.exists(path));
402+
assertFalse("No deletion", fs.delete(path, true));
403403
}
404404

405405
@Test
@@ -409,35 +409,35 @@ public void testDeleteRecursively() throws IOException {
409409
Path subdir = path("testDeleteRecursively/subdir");
410410

411411
createFile(file);
412-
assertTrue(fs.mkdirs(subdir), "Created subdir");
412+
assertTrue("Created subdir", fs.mkdirs(subdir));
413413

414-
assertTrue(fs.exists(file), "File exists");
415-
assertTrue(fs.exists(dir), "Dir exists");
416-
assertTrue(fs.exists(subdir), "Subdir exists");
414+
assertTrue("File exists", fs.exists(file));
415+
assertTrue("Dir exists", fs.exists(dir));
416+
assertTrue("Subdir exists", fs.exists(subdir));
417417

418418
try {
419419
fs.delete(dir, false);
420420
fail("Should throw IOException.");
421421
} catch (IOException e) {
422422
// expected
423423
}
424-
assertTrue(fs.exists(file), "File still exists");
425-
assertTrue(fs.exists(dir), "Dir still exists");
426-
assertTrue(fs.exists(subdir), "Subdir still exists");
424+
assertTrue("File still exists", fs.exists(file));
425+
assertTrue("Dir still exists", fs.exists(dir));
426+
assertTrue("Subdir still exists", fs.exists(subdir));
427427

428-
assertTrue(fs.delete(dir, true), "Deleted");
429-
assertFalse(fs.exists(file), "File doesn't exist");
430-
assertFalse(fs.exists(dir), "Dir doesn't exist");
431-
assertFalse(fs.exists(subdir), "Subdir doesn't exist");
428+
assertTrue("Deleted", fs.delete(dir, true));
429+
assertFalse("File doesn't exist", fs.exists(file));
430+
assertFalse("Dir doesn't exist", fs.exists(dir));
431+
assertFalse("Subdir doesn't exist", fs.exists(subdir));
432432
}
433433

434434
@Test
435435
public void testDeleteEmptyDirectory() throws IOException {
436436
Path dir = path("testDeleteEmptyDirectory");
437437
assertTrue(fs.mkdirs(dir));
438-
assertTrue(fs.exists(dir), "Dir exists");
439-
assertTrue(fs.delete(dir, false), "Deleted");
440-
assertFalse(fs.exists(dir), "Dir doesn't exist");
438+
assertTrue("Dir exists", fs.exists(dir));
439+
assertTrue("Deleted", fs.delete(dir, false));
440+
assertFalse("Dir doesn't exist", fs.exists(dir));
441441
}
442442

443443
@Test
@@ -516,14 +516,14 @@ public void testRenameDirectoryMoveToExistingDirectory() throws Exception {
516516
fs.mkdirs(dst.getParent());
517517
rename(src, dst, true, false, true);
518518

519-
assertFalse(
520-
fs.exists(path(src + "/file1")), "Nested file1 exists");
521-
assertFalse(
522-
fs.exists(path(src + "/subdir/file2")), "Nested file2 exists");
523-
assertTrue(
524-
fs.exists(path(dst + "/file1")), "Renamed nested file1 exists");
525-
assertTrue(
526-
fs.exists(path(dst + "/subdir/file2")), "Renamed nested exists");
519+
assertFalse("Nested file1 exists",
520+
fs.exists(path(src + "/file1")));
521+
assertFalse("Nested file2 exists",
522+
fs.exists(path(src + "/subdir/file2")));
523+
assertTrue("Renamed nested file1 exists",
524+
fs.exists(path(dst + "/file1")));
525+
assertTrue("Renamed nested exists",
526+
fs.exists(path(dst + "/subdir/file2")));
527527
}
528528

529529
@Test
@@ -548,16 +548,16 @@ public void testRenameDirectoryAsExistingDirectory() throws Exception {
548548
final Path dst = path("testRenameDirectoryAsExistingDirectoryNew/newdir");
549549
fs.mkdirs(dst);
550550
rename(src, dst, true, false, true);
551-
assertTrue(
552-
fs.exists(path(dst + "/dir")), "Destination changed");
553-
assertFalse(
554-
fs.exists(path(src + "/file1")), "Nested file1 exists");
555-
assertFalse(
556-
fs.exists(path(src + "/dir/subdir/file2")), "Nested file2 exists");
557-
assertTrue(
558-
fs.exists(path(dst + "/dir/file1")), "Renamed nested file1 exists");
559-
assertTrue(
560-
fs.exists(path(dst + "/dir/subdir/file2")), "Renamed nested exists");
551+
assertTrue("Destination changed",
552+
fs.exists(path(dst + "/dir")));
553+
assertFalse("Nested file1 exists",
554+
fs.exists(path(src + "/file1")));
555+
assertFalse("Nested file2 exists",
556+
fs.exists(path(src + "/dir/subdir/file2")));
557+
assertTrue("Renamed nested file1 exists",
558+
fs.exists(path(dst + "/dir/file1")));
559+
assertTrue("Renamed nested exists",
560+
fs.exists(path(dst + "/dir/subdir/file2")));
561561
}
562562

563563
@Test
@@ -590,9 +590,9 @@ protected void createFile(Path path) throws IOException {
590590

591591
protected void rename(Path src, Path dst, boolean renameSucceeded,
592592
boolean srcExists, boolean dstExists) throws IOException {
593-
assertEquals(renameSucceeded, fs.rename(src, dst), "Rename result");
594-
assertEquals(srcExists, fs.exists(src), "Source exists");
595-
assertEquals(dstExists, fs.exists(dst), "Destination exists" + dst);
593+
assertEquals("Rename result", renameSucceeded, fs.rename(src, dst));
594+
assertEquals("Source exists", srcExists, fs.exists(src));
595+
assertEquals("Destination exists" + dst, dstExists, fs.exists(dst));
596596
}
597597

598598
/**
@@ -633,27 +633,27 @@ public void testFilesystemIsCaseSensitive() throws Exception {
633633
String mixedCaseFilename = "testFilesystemIsCaseSensitive";
634634
Path upper = path(mixedCaseFilename);
635635
Path lower = path(StringUtils.toLowerCase(mixedCaseFilename));
636-
assertFalse(fs.exists(upper), "File exists" + upper);
637-
assertFalse(fs.exists(lower), "File exists" + lower);
636+
assertFalse("File exists" + upper, fs.exists(upper));
637+
assertFalse("File exists" + lower, fs.exists(lower));
638638
FSDataOutputStream out = fs.create(upper);
639639
out.writeUTF("UPPER");
640640
out.close();
641641
FileStatus upperStatus = fs.getFileStatus(upper);
642-
assertTrue(fs.exists(upper), "File does not exist" + upper);
642+
assertTrue("File does not exist" + upper, fs.exists(upper));
643643
//verify the lower-case version of the filename doesn't exist
644-
assertFalse(fs.exists(lower), "File exists" + lower);
644+
assertFalse("File exists" + lower, fs.exists(lower));
645645
//now overwrite the lower case version of the filename with a
646646
//new version.
647647
out = fs.create(lower);
648648
out.writeUTF("l");
649649
out.close();
650-
assertTrue(fs.exists(lower), "File does not exist" + lower);
650+
assertTrue("File does not exist" + lower, fs.exists(lower));
651651
//verify the length of the upper file hasn't changed
652652
FileStatus newStatus = fs.getFileStatus(upper);
653-
assertEquals(
654-
upperStatus.getLen()
655-
, newStatus.getLen(), "Expected status:" + upperStatus
656-
+ " actual status " + newStatus); }
653+
assertEquals("Expected status:" + upperStatus
654+
+ " actual status " + newStatus,
655+
upperStatus.getLen(),
656+
newStatus.getLen()); }
657657

658658
/**
659659
* Asserts that a zero byte file has a status of file and not
@@ -693,7 +693,7 @@ public void testRootDirAlwaysExists() throws Exception {
693693
fs.getFileStatus(path("/"));
694694
//this catches overrides of the base exists() method that don't
695695
//use getFileStatus() as an existence probe
696-
assertTrue(fs.exists(path("/")), "FileSystem.exists() fails for root");
696+
assertTrue("FileSystem.exists() fails for root", fs.exists(path("/")));
697697
}
698698

699699
/**
@@ -789,8 +789,8 @@ public void testMoveDirUnderParent() throws Throwable {
789789
Path parent = testdir.getParent();
790790
//the outcome here is ambiguous, so is not checked
791791
fs.rename(testdir, parent);
792-
assertEquals(true, fs.exists(testdir), "Source exists: " + testdir);
793-
assertEquals(true, fs.exists(parent), "Destination exists" + parent);
792+
assertEquals("Source exists: " + testdir, true, fs.exists(testdir));
793+
assertEquals("Destination exists" + parent, true, fs.exists(parent));
794794
}
795795

796796
/**
@@ -855,9 +855,9 @@ private void assertListFilesFinds(Path dir, Path subdir) throws IOException {
855855
found = true;
856856
}
857857
}
858-
assertTrue(
859-
found, "Path " + subdir
860-
+ " not found in directory " + dir + ":" + builder);
858+
assertTrue("Path " + subdir
859+
+ " not found in directory " + dir + ":" + builder,
860+
found);
861861
}
862862

863863
protected void assertListStatusFinds(Path dir, Path subdir)
@@ -871,9 +871,9 @@ protected void assertListStatusFinds(Path dir, Path subdir)
871871
found = true;
872872
}
873873
}
874-
assertTrue(
875-
found, "Path " + subdir
876-
+ " not found in directory " + dir + ":" + builder);
874+
assertTrue("Path " + subdir
875+
+ " not found in directory " + dir + ":" + builder,
876+
found);
877877
}
878878

879879

@@ -884,14 +884,14 @@ protected void assertListStatusFinds(Path dir, Path subdir)
884884
* @throws IOException IO problems during file operations
885885
*/
886886
private void assertIsFile(Path filename) throws IOException {
887-
assertTrue(fs.exists(filename), "Does not exist: " + filename);
887+
assertTrue("Does not exist: " + filename, fs.exists(filename));
888888
FileStatus status = fs.getFileStatus(filename);
889889
String fileInfo = filename + " " + status;
890-
assertTrue(status.isFile(), "Not a file " + fileInfo);
891-
assertFalse(
892-
status.isSymlink(), "File claims to be a symlink " + fileInfo);
893-
assertFalse(
894-
status.isDirectory(), "File claims to be a directory " + fileInfo);
890+
assertTrue("Not a file " + fileInfo, status.isFile());
891+
assertFalse("File claims to be a symlink " + fileInfo,
892+
status.isSymlink());
893+
assertFalse("File claims to be a directory " + fileInfo,
894+
status.isDirectory());
895895
}
896896

897897
/**
@@ -918,8 +918,8 @@ private void assertIsFile(Path filename) throws IOException {
918918
protected void writeAndRead(Path path, byte[] src, int len,
919919
boolean overwrite,
920920
boolean delete) throws IOException {
921-
assertTrue(
922-
src.length >= len, "Not enough data in source array to write " + len + " bytes");
921+
assertTrue("Not enough data in source array to write " + len + " bytes",
922+
src.length >= len);
923923
fs.mkdirs(path.getParent());
924924

925925
FSDataOutputStream out = fs.create(path, overwrite,
@@ -929,8 +929,8 @@ protected void writeAndRead(Path path, byte[] src, int len,
929929
out.write(src, 0, len);
930930
out.close();
931931

932-
assertTrue(fs.exists(path), "Exists");
933-
assertEquals(len, fs.getFileStatus(path).getLen(), "Length");
932+
assertTrue("Exists", fs.exists(path));
933+
assertEquals("Length", len, fs.getFileStatus(path).getLen());
934934

935935
FSDataInputStream in = fs.open(path);
936936
byte[] buf = new byte[len];
@@ -978,8 +978,8 @@ protected void writeAndRead(Path path, byte[] src, int len,
978978

979979
if (delete) {
980980
boolean deleted = fs.delete(path, false);
981-
assertTrue(deleted, "Deleted");
982-
assertFalse(fs.exists(path), "No longer exists");
981+
assertTrue("Deleted", deleted);
982+
assertFalse("No longer exists", fs.exists(path));
983983
}
984984
}
985985

0 commit comments

Comments
 (0)