@@ -365,6 +365,63 @@ void replaceNonEmptyDirectory() throws IOException {
365365 assertThrows (DirectoryNotEmptyException .class , () -> fs .rename ("/src" , "/dst" , true ));
366366 }
367367
368+ @ Test
369+ @ DisplayName ("a missing source leaves the target untouched" )
370+ void missingSource () throws IOException {
371+ fs .createDirectory ("/dst" , Set .of ());
372+ fs .createSymbolicLink ("/link" , "t" );
373+
374+ assertThrows (NoSuchFileException .class , () -> fs .rename ("/missing" , "/dst" , true ));
375+ assertThrows (NoSuchFileException .class , () -> fs .rename ("/missing" , "/link" , true ));
376+
377+ assertEquals (VfsNodeType .DIRECTORY , fs .readNodeMetadata ("/dst" ).type ());
378+ assertEquals ("t" , fs .readSymbolicLink ("/link" ));
379+ }
380+
381+ @ Test
382+ @ DisplayName ("renaming onto itself keeps the node" )
383+ void ontoItself () throws IOException {
384+ fs .createDirectory ("/d" , Set .of ());
385+ writeFile ("/d/f" , "x" );
386+ fs .createSymbolicLink ("/link" , "t" );
387+
388+ fs .rename ("/d" , "/d" , true );
389+ fs .rename ("/link" , "/link" , true );
390+
391+ assertEquals ("x" , readFile ("/d/f" ));
392+ assertEquals ("t" , fs .readSymbolicLink ("/link" ));
393+ }
394+
395+ @ Test
396+ @ DisplayName ("a symbolic link replaces a file and vice versa" )
397+ void symlinkAndFileReplaceEachOther () throws IOException {
398+ fs .createSymbolicLink ("/link" , "t" );
399+ writeFile ("/f" , "x" );
400+ fs .createSymbolicLink ("/link2" , "u" );
401+ writeFile ("/g" , "y" );
402+
403+ fs .rename ("/link" , "/f" , true );
404+ fs .rename ("/g" , "/link2" , true );
405+
406+ assertEquals ("t" , fs .readSymbolicLink ("/f" ));
407+ assertEquals ("y" , readFile ("/link2" ));
408+ assertThrows (NoSuchFileException .class , () -> fs .readNodeMetadata ("/link" ));
409+ assertThrows (NoSuchFileException .class , () -> fs .readNodeMetadata ("/g" ));
410+ }
411+
412+ @ Test
413+ @ DisplayName ("directories and symbolic links never replace each other" )
414+ void directoryAndSymlink () throws IOException {
415+ fs .createDirectory ("/d" , Set .of ());
416+ fs .createSymbolicLink ("/link" , "t" );
417+
418+ assertThrows (FileSystemException .class , () -> fs .rename ("/d" , "/link" , true ));
419+ assertThrows (FileSystemException .class , () -> fs .rename ("/link" , "/d" , true ));
420+
421+ assertEquals (VfsNodeType .DIRECTORY , fs .readNodeMetadata ("/d" ).type ());
422+ assertEquals ("t" , fs .readSymbolicLink ("/link" ));
423+ }
424+
368425 @ Test
369426 @ DisplayName ("refuses to move a directory into its own subtree" )
370427 void intoItself () throws IOException {
0 commit comments