117117import static org .apache .hadoop .ozone .OzoneConsts .OZONE_URI_DELIMITER ;
118118import static org .apache .hadoop .ozone .om .exceptions .OMException .ResultCodes .KEY_NOT_FOUND ;
119119import static org .apache .hadoop .ozone .om .helpers .BucketLayout .FILE_SYSTEM_OPTIMIZED ;
120+ import static org .assertj .core .api .Assertions .assertThat ;
120121import static org .junit .jupiter .api .Assertions .assertEquals ;
121122import static org .junit .jupiter .api .Assertions .assertFalse ;
122123import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
@@ -392,7 +393,7 @@ private void checkInvalidPath(Path path) {
392393 InvalidPathException pathException = assertThrows (
393394 InvalidPathException .class , () -> fs .create (path , false )
394395 );
395- assertTrue (pathException .getMessage ().contains ("Invalid path Name" ) );
396+ assertThat (pathException .getMessage ()) .contains ("Invalid path Name" );
396397 }
397398
398399 @ Test
@@ -466,7 +467,7 @@ public void testRecursiveDelete() throws Exception {
466467 // delete a dir with sub-file
467468 try {
468469 FileStatus [] parents = fs .listStatus (grandparent );
469- assertTrue (parents .length > 0 );
470+ assertThat (parents .length ). isGreaterThan ( 0 );
470471 fs .delete (parents [0 ].getPath (), false );
471472 fail ("Must throw exception as dir is not empty!" );
472473 } catch (PathIsNotEmptyDirectoryException pde ) {
@@ -537,8 +538,8 @@ private void checkPath(Path path) {
537538 fs .getFileStatus (path );
538539 fail ("testRecursiveDelete failed" );
539540 } catch (IOException ex ) {
540- assertTrue ( ex instanceof FileNotFoundException );
541- assertTrue (ex .getMessage ().contains ("No such file or directory" ) );
541+ assertInstanceOf ( FileNotFoundException . class , ex );
542+ assertThat (ex .getMessage ()) .contains ("No such file or directory" );
542543 }
543544 }
544545
@@ -748,7 +749,7 @@ public void testListStatusOnLargeDirectory() throws Exception {
748749 assertEquals (numDirs , fileStatuses .length , "Total directories listed do not match the existing directories" );
749750
750751 for (int i = 0 ; i < numDirs ; i ++) {
751- assertTrue (paths .contains (fileStatuses [i ].getPath ().getName () ));
752+ assertThat (paths ) .contains (fileStatuses [i ].getPath ().getName ());
752753 }
753754 }
754755
@@ -1003,7 +1004,7 @@ public void testSeekOnFileLength() throws IOException {
10031004 fs .open (fileNotExists );
10041005 fail ("Should throw FileNotFoundException as file doesn't exist!" );
10051006 } catch (FileNotFoundException fnfe ) {
1006- assertTrue (fnfe .getMessage ().contains ("KEY_NOT_FOUND" ), "Expected KEY_NOT_FOUND error " );
1007+ assertThat (fnfe .getMessage ()) .contains ("KEY_NOT_FOUND" );
10071008 }
10081009 }
10091010
@@ -1026,12 +1027,16 @@ public void testAllocateMoreThanOneBlock() throws IOException {
10261027 FileStatus fileStatus = fs .getFileStatus (file );
10271028 long blkSize = fileStatus .getBlockSize ();
10281029 long fileLength = fileStatus .getLen ();
1029- assertTrue (fileLength > blkSize , "Block allocation should happen" );
1030+ assertThat (fileLength )
1031+ .withFailMessage ("Block allocation should happen" )
1032+ .isGreaterThan (blkSize );
10301033
10311034 long newNumBlockAllocations =
10321035 cluster .getOzoneManager ().getMetrics ().getNumBlockAllocates ();
10331036
1034- assertTrue ((newNumBlockAllocations > numBlockAllocationsOrg ), "Block allocation should happen" );
1037+ assertThat (newNumBlockAllocations )
1038+ .withFailMessage ("Block allocation should happen" )
1039+ .isGreaterThan (numBlockAllocationsOrg );
10351040
10361041 stream .seek (fileLength );
10371042 assertEquals (-1 , stream .read ());
@@ -1366,7 +1371,7 @@ public void testRenameDir() throws Exception {
13661371 IllegalArgumentException exception = assertThrows (
13671372 IllegalArgumentException .class ,
13681373 () -> fs .rename (new Path (fs .getUri ().toString () + "fake" + dir ), dest ));
1369- assertTrue (exception .getMessage ().contains ("Wrong FS" ) );
1374+ assertThat (exception .getMessage ()) .contains ("Wrong FS" );
13701375 }
13711376
13721377 private OzoneKeyDetails getKey (Path keyPath , boolean isDirectory )
@@ -1419,7 +1424,7 @@ public void testGetDirectoryModificationTime()
14191424 for (int i = 0 ; i < 5 ; i ++) {
14201425 Thread .sleep (10 );
14211426 fileStatuses = o3fs .listStatus (mdir1 );
1422- assertTrue (modificationTime <= fileStatuses [0 ].getModificationTime ());
1427+ assertThat (modificationTime ). isLessThanOrEqualTo ( fileStatuses [0 ].getModificationTime ());
14231428 }
14241429 }
14251430
@@ -1817,7 +1822,7 @@ public void testOzFsReadWrite() throws IOException {
18171822
18181823 // The timestamp of the newly created file should always be greater than
18191824 // the time when the test was started
1820- assertTrue (status .getModificationTime () > currentTime );
1825+ assertThat (status .getModificationTime ()). isGreaterThan ( currentTime );
18211826
18221827 assertFalse (status .isDirectory ());
18231828 assertEquals (FsPermission .getFileDefault (), status .getPermission ());
@@ -1968,7 +1973,7 @@ void testListStatus2() throws IOException {
19681973 assertChange (initialStats , statistics , Statistic .OBJECTS_LIST .getSymbol (), 2 );
19691974 assertEquals (initialListStatusCount + 2 , omMetrics .getNumListStatus ());
19701975 for (Path p : paths ) {
1971- assertTrue (Arrays .asList (statusList ).contains (fs .getFileStatus (p ) ));
1976+ assertThat (Arrays .asList (statusList )) .contains (fs .getFileStatus (p ));
19721977 }
19731978 }
19741979
@@ -2006,7 +2011,7 @@ void testOzoneManagerFileSystemInterface() throws IOException {
20062011 // doesn't actually exist on server; if it exists, it will be a fixed value.
20072012 // In this case, the dir key exists.
20082013 assertEquals (0 , omStatus .getKeyInfo ().getDataSize ());
2009- assertTrue (omStatus .getKeyInfo ().getModificationTime () <= currentTime );
2014+ assertThat (omStatus .getKeyInfo ().getModificationTime ()). isLessThanOrEqualTo ( currentTime );
20102015 assertEquals (new Path (omStatus .getPath ()).getName (),
20112016 o3fs .pathToKey (path ));
20122017 }
@@ -2020,13 +2025,12 @@ public void testOzoneManagerLocatedFileStatus() throws IOException {
20202025 stream .writeBytes (data );
20212026 }
20222027 FileStatus status = fs .getFileStatus (path );
2023- assertTrue (status instanceof LocatedFileStatus );
2024- LocatedFileStatus locatedFileStatus = (LocatedFileStatus ) status ;
2025- assertTrue (locatedFileStatus .getBlockLocations ().length >= 1 );
2028+ LocatedFileStatus locatedFileStatus = assertInstanceOf (LocatedFileStatus .class , status );
2029+ assertThat (locatedFileStatus .getBlockLocations ().length ).isGreaterThanOrEqualTo (1 );
20262030
20272031 for (BlockLocation blockLocation : locatedFileStatus .getBlockLocations ()) {
2028- assertTrue (blockLocation .getNames ().length >= 1 );
2029- assertTrue (blockLocation .getHosts ().length >= 1 );
2032+ assertThat (blockLocation .getNames ().length ). isGreaterThanOrEqualTo ( 1 );
2033+ assertThat (blockLocation .getHosts ().length ). isGreaterThanOrEqualTo ( 1 );
20302034 }
20312035 }
20322036
@@ -2046,8 +2050,7 @@ void testBlockOffsetsWithMultiBlockFile() throws Exception {
20462050 stream .writeBytes (data );
20472051 }
20482052 FileStatus status = fs .getFileStatus (path );
2049- assertTrue (status instanceof LocatedFileStatus );
2050- LocatedFileStatus locatedFileStatus = (LocatedFileStatus ) status ;
2053+ LocatedFileStatus locatedFileStatus = assertInstanceOf (LocatedFileStatus .class , status );
20512054 BlockLocation [] blockLocations = locatedFileStatus .getBlockLocations ();
20522055
20532056 assertEquals (0 , blockLocations [0 ].getOffset ());
@@ -2099,7 +2102,7 @@ void testFileSystemWithObjectStoreLayout() throws IOException {
20992102 config .set (FS_DEFAULT_NAME_KEY , obsRootPath );
21002103
21012104 IllegalArgumentException e = assertThrows (IllegalArgumentException .class , () -> FileSystem .get (config ));
2102- assertTrue (e .getMessage ().contains ("OBJECT_STORE, which does not support file system semantics" ) );
2105+ assertThat (e .getMessage ()) .contains ("OBJECT_STORE, which does not support file system semantics" );
21032106 }
21042107 }
21052108
0 commit comments