@@ -451,30 +451,21 @@ public static void deleteDir(File dir)
451451 * @param sourceDir the directory to rename
452452 * @param newDirName the new name for the directory
453453 */
454- public static void renameDir (Path sourceDir , String newDirName )
454+ public static void renameDir (Path sourceDir , String newDirName ) throws IOException
455455 {
456456 LOG .info ("Renaming {} to {}" , sourceDir , newDirName );
457457
458458 // Check if the directory is outside the test enlistment.
459459 checkFileLocation (sourceDir .toFile ());
460460
461- Assert .assertTrue (sourceDir + " does not exists." , sourceDir .toFile ().exists ());
461+ Assert .assertTrue ("Directory does not exist: " + sourceDir , sourceDir .toFile ().exists ());
462462
463- try
464- {
465- // Get the separator appropriate for the given OS.
466- String separator = File .separator ;
467- int lastIndex = sourceDir .toString ().lastIndexOf (separator );
468- Path newDir = lastIndex <= 0 ?
469- Paths .get (separator + newDirName ) :
470- Paths .get (sourceDir .toString ().substring (0 , lastIndex ) + separator + newDirName );
471- Files .move (sourceDir , newDir );
472- LOG .info ("Rename successful." );
473- }
474- catch (IOException e )
475- {
476- LOG .info ("WARNING: Exception renaming directory -- " + e .getMessage ());
477- }
463+ Path newDir = sourceDir .getParent () != null
464+ ? sourceDir .getParent ().resolve (newDirName )
465+ : Paths .get (newDirName );
466+ Files .move (sourceDir , newDir );
467+
468+ LOG .info ("Rename successful." );
478469 }
479470
480471 private static void checkFileLocation (File file )
0 commit comments