CompressionUtil { public static File compress(File sourceFile, String algorithm, boolean deleteSourceFileAfterCompressed) throws FileAlreadyExistsException, IOException { return compress(sourceFile, sourceFile.getParentFile(), algorithm, deleteSourceFileAfterCompressed); }  static boolean isAlgorithmSupported(String algorithm); static boolean isFileExtensionSupported(String fileExt); static File compress(File sourceFile, String algorithm, boolean deleteSourceFileAfterCompressed); static File compress(File sourceFile, File targetDir, String algorithm, boolean deleteSourceFileAfterCompressed); static File uncompress(File sourceFile, boolean deleteSourceFileAfterUncompressed); static File uncompress(File sourceFile, File targetDir, boolean deleteSourceFileAfterUncompressed);  }
@Test public void compressNoOverwrite() throws Exception { File originalSourceFile = new File(TEST_FILE); File sourceFile = new File("target", originalSourceFile.getName()); FileUtil.copy(originalSourceFile, sourceFile, true); Algorithm a = Algorithm.findByName("gzip"); File expectedCompressedFile = new File(sourceFile.getParentFile(), sourceFile.getName() + "." + a.getFileExtension()); expectedCompressedFile.delete(); CompressionUtil.compress(sourceFile, a.getName(), false); try { CompressionUtil.compress(sourceFile, a.getName(), false); Assert.fail("Should have failed"); } catch (FileAlreadyExistsException e) { } }