@Test public void testBackupFile(@Mocked final Files unused, @Injectable Path mockFile) { new Expectations() { { backupDir.toFile().exists(); result = true; } }; try { OdeFileUtils.backupFile(mockFile, backupDir); } catch (Exception e) { fail("Unexpected exception: " + e); } }
public static void backupFile(Path file, Path backupDir) throws IOException { if (!backupDir.toFile().exists()) { throw new IOException("Backup directory does not exist: " + backupDir); } String processedFileName = Integer.toString((int) System.currentTimeMillis()) + "-" + file.getFileName().toString().replaceFirst("uper", "pbo"); Path targetPath = Paths.get(backupDir.toString(), processedFileName); try { Files.move(file, targetPath, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new IOException("Unable to move file to backup: " + e); } }
OdeFileUtils { public static void backupFile(Path file, Path backupDir) throws IOException { if (!backupDir.toFile().exists()) { throw new IOException("Backup directory does not exist: " + backupDir); } String processedFileName = Integer.toString((int) System.currentTimeMillis()) + "-" + file.getFileName().toString().replaceFirst("uper", "pbo"); Path targetPath = Paths.get(backupDir.toString(), processedFileName); try { Files.move(file, targetPath, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new IOException("Unable to move file to backup: " + e); } } }
OdeFileUtils { public static void backupFile(Path file, Path backupDir) throws IOException { if (!backupDir.toFile().exists()) { throw new IOException("Backup directory does not exist: " + backupDir); } String processedFileName = Integer.toString((int) System.currentTimeMillis()) + "-" + file.getFileName().toString().replaceFirst("uper", "pbo"); Path targetPath = Paths.get(backupDir.toString(), processedFileName); try { Files.move(file, targetPath, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new IOException("Unable to move file to backup: " + e); } } private  OdeFileUtils(); }
OdeFileUtils { public static void backupFile(Path file, Path backupDir) throws IOException { if (!backupDir.toFile().exists()) { throw new IOException("Backup directory does not exist: " + backupDir); } String processedFileName = Integer.toString((int) System.currentTimeMillis()) + "-" + file.getFileName().toString().replaceFirst("uper", "pbo"); Path targetPath = Paths.get(backupDir.toString(), processedFileName); try { Files.move(file, targetPath, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new IOException("Unable to move file to backup: " + e); } } private  OdeFileUtils(); static void createDirectoryRecursively(Path dir); static void backupFile(Path file, Path backupDir); static void moveFile(Path file, Path destination); }
OdeFileUtils { public static void backupFile(Path file, Path backupDir) throws IOException { if (!backupDir.toFile().exists()) { throw new IOException("Backup directory does not exist: " + backupDir); } String processedFileName = Integer.toString((int) System.currentTimeMillis()) + "-" + file.getFileName().toString().replaceFirst("uper", "pbo"); Path targetPath = Paths.get(backupDir.toString(), processedFileName); try { Files.move(file, targetPath, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new IOException("Unable to move file to backup: " + e); } } private  OdeFileUtils(); static void createDirectoryRecursively(Path dir); static void backupFile(Path file, Path backupDir); static void moveFile(Path file, Path destination);  }