RetrievalWorker implements Runnable { protected File renameFile(File localFile) throws IOException { File origFile = new File(localFile.getAbsolutePath()); File copiedFile = new File(localFile.getParent(), localFile.getName() + COPY); for (int i = 2; copiedFile.exists(); i++) { copiedFile = new File(localFile.getParent(), localFile.getName() + COPY + "-" + i); } FileUtils.moveFile(origFile, copiedFile); return copiedFile; } RetrievalWorker(ContentItem contentItem,
                           RetrievalSource source,
                           File contentDir,
                           boolean overwrite,
                           OutputWriter outWriter,
                           boolean createSpaceDir,
                           boolean applyTimestamps); void run(); Map<String, String> retrieveFile(); Map<String, String> retrieveFile(RetrievalListener listener); File getLocalFile();  }
@Test public void testRenameFile() throws Exception { RetrievalWorker worker = createRetrievalWorker(true); File localFile = new File(tempDir, "rename-test"); String localFilePath = localFile.getAbsolutePath(); FileUtils.writeStringToFile(localFile, "test"); File newFile = worker.renameFile(localFile); assertEquals(localFilePath, localFile.getAbsolutePath()); assertFalse(localFile.exists()); assertTrue(newFile.exists()); assertEquals(localFile.getAbsolutePath() + "-copy", newFile.getAbsolutePath()); FileUtils.writeStringToFile(localFile, "test"); File newFile2 = worker.renameFile(localFile); assertEquals(localFilePath, localFile.getAbsolutePath()); assertFalse(localFile.exists()); assertTrue(newFile2.exists()); assertEquals(localFile.getAbsolutePath() + "-copy-2", newFile2.getAbsolutePath()); }