### Question:
FileMoveProvider { public Stream<FileMoveAction> traverseForMoving( File dir ) { return traverseForMoving( dir, dir ); } FileMoveProvider( FileSystemAbstraction fs ); Stream<FileMoveAction> traverseForMoving( File dir );  }### Answer:
@Test public void moveSingleFiles() throws IOException { File sharedParent = testDirectory.cleanDirectory( "shared_parent" ); File sourceParent = new File( sharedParent, "source" ); assertTrue( sourceParent.mkdirs() ); File sourceFile = new File( sourceParent, "file.txt" ); assertTrue( sourceFile.createNewFile() ); writeToFile( sourceFile, "Garbage data" ); File targetParent = new File( sharedParent, "target" ); assertTrue( targetParent.mkdirs() ); File targetFile = new File( targetParent, "file.txt" ); subject.traverseForMoving( sourceFile ).forEach( moveToDirectory( targetParent ) ); assertEquals( "Garbage data", readFromFile( targetFile ) ); }
@Test public void singleDirectoriesAreNotMoved() throws IOException { File sharedParent = testDirectory.cleanDirectory( "shared_parent" ); File sourceParent = new File( sharedParent, "source" ); assertTrue( sourceParent.mkdirs() ); File sourceDirectory = new File( sourceParent, "directory" ); assertTrue( sourceDirectory.mkdirs() ); File targetParent = new File( sharedParent, "target" ); assertTrue( targetParent.mkdirs() ); File targetDirectory = new File( targetParent, "directory" ); assertFalse( targetDirectory.exists() ); subject.traverseForMoving( sourceParent ).forEach( moveToDirectory( targetDirectory ) ); assertTrue( sourceDirectory.exists() ); assertFalse( targetDirectory.exists() ); }
@Test public void moveNestedFiles() throws IOException { File sharedParent = testDirectory.cleanDirectory( "shared_parent" ); File sourceParent = new File( sharedParent, "source" ); assertTrue( sourceParent.mkdirs() ); File targetParent = new File( sharedParent, "target" ); assertTrue( targetParent.mkdirs() ); File dirA = new File( sourceParent, "A" ); assertTrue( dirA.mkdirs() ); File nestedFileOne = new File( dirA, "file.txt" ); assertTrue( nestedFileOne.createNewFile() ); File dirB = new File( sourceParent, "B" ); assertTrue( dirB.mkdirs() ); File nestedFileTwo = new File( dirB, "file.txt" ); assertTrue( nestedFileTwo.createNewFile() ); writeToFile( nestedFileOne, "This is the file contained in directory A" ); writeToFile( nestedFileTwo, "This is the file contained in directory B" ); File targetFileOne = new File( targetParent, "A/file.txt" ); File targetFileTwo = new File( targetParent, "B/file.txt" ); subject.traverseForMoving( sourceParent ).forEach( moveToDirectory( targetParent ) ); assertEquals( "This is the file contained in directory A", readFromFile( targetFileOne ) ); assertEquals( "This is the file contained in directory B", readFromFile( targetFileTwo ) ); }
@Test public void filesAreMovedBeforeDirectories() throws IOException { File parentDirectory = testDirectory.cleanDirectory( "parent" ); File sourceDirectory = new File( parentDirectory, "source" ); assertTrue( sourceDirectory.mkdirs() ); File childFile = new File( sourceDirectory, "child" ); assertTrue( childFile.createNewFile() ); writeToFile( childFile, "Content" ); File targetDirectory = new File( parentDirectory, "target" ); assertTrue( targetDirectory.mkdirs() ); subject.traverseForMoving( sourceDirectory ).forEach( moveToDirectory( targetDirectory ) ); }