FileSystemUtils { public static <F> F copyFile(IBasicFileSystem<F> fileSystem, F file, String destinationFolder, boolean overwrite, int numOfBackups, boolean createFolders) throws FileSystemException { prepareDestination(fileSystem, file, destinationFolder, overwrite, numOfBackups, createFolders); F newFile = fileSystem.copyFile(file, destinationFolder, createFolders); if (newFile == null) { throw new FileSystemException("cannot copy file [" + fileSystem.getName(file) + "] to [" + destinationFolder + "]"); } return newFile; }  static void prepareDestination(IBasicFileSystem<F> fileSystem, F file, String destinationFolder, boolean overwrite, int numOfBackups, boolean createFolders); static F moveFile(IBasicFileSystem<F> fileSystem, F file, String destinationFolder, boolean overwrite, int numOfBackups, boolean createFolders); static F copyFile(IBasicFileSystem<F> fileSystem, F file, String destinationFolder, boolean overwrite, int numOfBackups, boolean createFolders); static void rolloverByNumber(IWritableFileSystem<F> fileSystem, F file, int numberOfBackups); static void rolloverByNumber(IWritableFileSystem<F> fileSystem, String folder, String filename, int numberOfBackups); static void rolloverBySize(IWritableFileSystem<F> fileSystem, F file, int rotateSize, int numberOfBackups); static void rolloverBySize(IWritableFileSystem<F> fileSystem, F file, String folder, int rotateSize, int numberOfBackups); static void rolloverByDay(IWritableFileSystem<F> fileSystem, F file, String folder, int rotateDays);  }
@Test public void testCopyWithBackup() throws Exception { String filename = "backupTest" + FILE1; String contents = "text content:"; String srcFolder = "srcFolder"; String dstFolder = "dstFolder"; int numOfBackups=3; int numOfFilesPresentAtStart=5; if (_fileExists(filename)) { _deleteFile(dstFolder, filename); } if (dstFolder!=null) { if (_folderExists(dstFolder)) { _createFolder(dstFolder); } } for (int i=1;i<=numOfFilesPresentAtStart;i++) { createFile(dstFolder, filename+"."+i,contents+i); } createFile(dstFolder, filename,contents+"0"); createFile(srcFolder, filename,contents+"new"); F file = fileSystem.toFile(srcFolder, filename); assertFileExistsWithContents(dstFolder, filename, contents.trim()+"0"); assertFileExistsWithContents(dstFolder, filename+"."+numOfFilesPresentAtStart, contents.trim()+(numOfFilesPresentAtStart)); FileSystemUtils.copyFile(fileSystem, file, dstFolder, false, numOfBackups, false); assertFileExistsWithContents(srcFolder, filename, contents.trim()+"new"); assertFileExistsWithContents(dstFolder, filename, contents.trim()+"new"); for (int i=1;i<=numOfBackups;i++) { assertFileExistsWithContents(dstFolder, filename+"."+i, contents.trim()+(i-1)); } assertFileDoesNotExist(dstFolder, filename+(numOfBackups+1)); assertFileDoesNotExist(dstFolder, filename+(numOfBackups+2)); }