@Test void streamFilesRecursiveMustRenameFiles() throws Exception { File a = existingFile( "a" ); File b = nonExistingFile( "b" ); // does not yet exist File base = a.getParentFile(); fsa.streamFilesRecursive( base ).forEach( handleRename( b ) ); List<File> filepaths = fsa.streamFilesRecursive( base ).map( FileHandle::getFile ).collect( toList() ); assertThat( filepaths, containsInAnyOrder( b.getCanonicalFile() ) ); }
@Test void streamFilesRecursiveMustNotSeeFilesRenamedIntoSubDirectory() throws Exception { File a = existingFile( "a" ); File sub = existingDirectory( "sub" ); File target = new File( sub, "target" ); Set<File> observedFiles = new HashSet<>(); fsa.streamFilesRecursive( a.getParentFile() ).forEach( fh -> { File file = fh.getFile(); observedFiles.add( file ); if ( file.equals( a ) ) { handleRename( target ).accept( fh ); } } ); assertThat( observedFiles, containsInAnyOrder( a ) ); }
@Test void streamFilesRecursiveMustNotSeeFilesRenamedIntoBaseDirectory() throws Exception { File a = existingFile( "a" ); File sub = existingDirectory( "sub" ); File x = new File( sub, "x" ); ensureExists( x ); File target = nonExistingFile( "target" ); Set<File> observedFiles = new HashSet<>(); fsa.streamFilesRecursive( a.getParentFile() ).forEach( fh -> { File file = fh.getFile(); observedFiles.add( file ); if ( file.equals( x ) ) { handleRename( target ).accept( fh ); } } ); assertThat( observedFiles, containsInAnyOrder( a, x ) ); }
@Test void streamFilesRecursiveMustDeleteSubDirectoriesEmptiedByFileRename() throws Exception { File sub = existingDirectory( "sub" ); File x = new File( sub, "x" ); ensureExists( x ); File target = nonExistingFile( "target" ); fsa.streamFilesRecursive( sub ).forEach( handleRename( target ) ); assertFalse( fsa.isDirectory( sub ) ); assertFalse( fsa.fileExists( sub ) ); }
@Test void streamFilesRecursiveMustDeleteMultipleLayersOfSubDirectoriesIfTheyBecomeEmptyByRename() throws Exception { File sub = existingDirectory( "sub" ); File subsub = new File( sub, "subsub" ); ensureDirectoryExists( subsub ); File x = new File( subsub, "x" ); ensureExists( x ); File target = nonExistingFile( "target" ); fsa.streamFilesRecursive( sub ).forEach( handleRename( target ) ); assertFalse( fsa.isDirectory( subsub ) ); assertFalse( fsa.fileExists( subsub ) ); assertFalse( fsa.isDirectory( sub ) ); assertFalse( fsa.fileExists( sub ) ); }
@Test void streamFilesRecursiveMustNotDeleteDirectoriesAboveBaseDirectoryIfTheyBecomeEmptyByRename() throws Exception { File sub = existingDirectory( "sub" ); File subsub = new File( sub, "subsub" ); File subsubsub = new File( subsub, "subsubsub" ); ensureDirectoryExists( subsub ); ensureDirectoryExists( subsubsub ); File x = new File( subsubsub, "x" ); ensureExists( x ); File target = nonExistingFile( "target" ); fsa.streamFilesRecursive( subsub ).forEach( handleRename( target ) ); assertFalse( fsa.fileExists( subsubsub ) ); assertFalse( fsa.isDirectory( subsubsub ) ); assertFalse( fsa.fileExists( subsub ) ); assertFalse( fsa.isDirectory( subsub ) ); assertTrue( fsa.fileExists( sub ) ); assertTrue( fsa.isDirectory( sub ) ); }