ChecksumCalculator { public String calculate(String fileToCheck, String algorithm, Consumer<ProgressEntity> onChange) throws IOException { return calculate(new File(fileToCheck), algorithm, onChange); }  String calculate(String fileToCheck, String algorithm, Consumer<ProgressEntity> onChange); String calculate(File fileToCheck, String algorithm, Consumer<ProgressEntity> onChange);  }
@Test public void testChecksumCalculateGenerateAFileCheckMD5() throws IOException { File temporaryFile = File.createTempFile("testHash", "txt"); try (FileOutputStream fileOutputStream = new FileOutputStream(temporaryFile)) { fileOutputStream.write("TEST".getBytes()); } assertEquals("033bd94b1168d7e4f0d644c3c95e35bf", new ChecksumCalculator().calculate(temporaryFile, "MD5", e -> { })); }
@Test public void testChecksumCalculateGenerateAFileCheckSHA1() throws IOException { File temporaryFile = File.createTempFile("testHash", "txt"); try (FileOutputStream fileOutputStream = new FileOutputStream(temporaryFile)) { fileOutputStream.write("TEST".getBytes()); } assertEquals("984816fd329622876e14907634264e6f332e9fb3", new ChecksumCalculator().calculate(temporaryFile, "SHA1", e -> { })); }