### Question:
PathUtils { public static String computeFileContentHash(Path path) { String newHash = ""; if (path != null && path.toFile() != null) { for (int i = 0; i < 3; i++) { try { byte[] rawHash = HashUtil.hash(path.toFile()); if (rawHash != null) { newHash = base64Encode(rawHash); } break; } catch (IOException e) { e.printStackTrace(); try { Thread.sleep(3000); } catch (InterruptedException e1) { e1.printStackTrace(); } } } } return newHash; }  static String computeFileContentHash(Path path); static String base64Encode(byte[] bytes); static byte[] base64Decode(String data); static boolean isFileHidden(Path file); static Path getCommonPath(Path path1, Path path2);  }### Answer:
@Test public void testComputeFileContentHash() throws IOException { Path file = null; try { file = Paths.get(FileUtils.getTempDirectoryPath(), RandomStringUtils.randomAlphanumeric(24)); String content = "hello world"; String md5AsBase64 = "XrY7u+Ae7tCTyyK7j1rNww=="; Files.write(file, content.getBytes()); String hash = PathUtils.computeFileContentHash(file); assertEquals(md5AsBase64, hash); } finally { if (file != null) { Files.deleteIfExists(file); } } }
@Test public void testComputeFileContentHash_Null() throws IOException { String hash = PathUtils.computeFileContentHash(null); assertEquals(hash, ""); }
@Test public void testComputeFileContentHash_EmptyFile() throws IOException { Path file = null; try { file = Paths.get(FileUtils.getTempDirectoryPath(), RandomStringUtils.randomAlphanumeric(24)); Files.createFile(file); String hash = PathUtils.computeFileContentHash(file); String base64_md5 = "1B2M2Y8AsgTpgAmY7PhCfg=="; assertEquals(base64_md5, hash); } finally { if (file != null) { Files.deleteIfExists(file); } } }