HashCalculator { public String calculateSHA1(File resourceFile) throws IOException { return calculateHash(resourceFile, HashAlgorithm.SHA1); }  HashCalculationResult calculateSuperHash(File file); HashCalculationResult calculateSuperHash(byte[] bytes); String calculateSHA1(File resourceFile); String calculateHash(File resourceFile, HashAlgorithm algorithm); String calculateByteArraySHA1(byte[] byteArray); String calculateByteArrayHash(byte[] byteArray, HashAlgorithm algorithm); Map<ChecksumType, String> calculateJavaScriptHashes(File file); Map<ChecksumType, String> calculateJavaScriptHashes(byte[] byteArray); String calculateSha1ByGAVCoordinatesAndType(String groupId, String artifactId, String version,
                                                                DependencyType dependencyType); String calculateSha1ByNameVersionArchitectureAndType(String name, String version, String architecture,
                                                                DependencyType dependencyType); String calculateSha1ByNameVersionAndType(String name, String version, DependencyType dependencyType);  }
@Test public void testBomFiles() throws IOException { HashCalculator hashCalculator = new HashCalculator(); String filePath = getClass().getResource("/utf-bom/jquery-1.8.1-utf8.txt").getFile(); File file = new File(filePath); String filePathBom = getClass().getResource("/utf-bom/jquery-1.8.1-utf8bom.txt").getFile(); File fileBom = new File(filePathBom); String sha1 = hashCalculator.calculateSHA1(file); String sha1Bom = hashCalculator.calculateSHA1(fileBom); Assert.assertTrue(sha1.equals(sha1Bom)); }
@Test public void testSHA1() throws IOException { HashCalculator hashCalculator = new HashCalculator(); String filePath = getClass().getResource("/empty-file.txt").getFile(); File file = new File(URLDecoder.decode(filePath, "utf-8")); String sha1 = hashCalculator.calculateSHA1(file); Assert.assertEquals(EMPTY_FILE_SHA1, sha1); filePath = getClass().getResource("/non-empty-file.txt").getFile(); file = new File(URLDecoder.decode(filePath, "utf-8")); sha1 = hashCalculator.calculateSHA1(file); if (Platform.isWindows()) { Assert.assertEquals(WINDOWS_NON_EMPTY_FILE_SHA1, sha1); } else { Assert.assertEquals(UNIX_NON_EMPTY_FILE_SHA1, sha1); } }