ContentIdUtil { public static String getContentId(File file, File watchDir, String contentIdPrefix) { String contentId = file.getName(); if (null != watchDir) { URI relativeFileURI = watchDir.toURI().relativize(file.toURI()); contentId = relativeFileURI.getPath(); } if (null != contentIdPrefix) { contentId = contentIdPrefix + contentId; } return contentId; } private  ContentIdUtil(); static String getContentId(File file,
                                      File watchDir,
                                      String contentIdPrefix);  }
@Test public void testGetContentId() throws Exception { File watchDir = new File("a"); File file = new File("a/b/c", "file.txt"); String contentId = ContentIdUtil.getContentId(file, watchDir, null); Assert.assertEquals("b/c/file.txt", contentId); contentId = ContentIdUtil.getContentId(file, null, null); Assert.assertEquals("file.txt", contentId); }
@Test public void testGetContentIdPrefix() throws Exception { String prefix = "prefix/"; File watchDir = new File("a"); File file = new File("a/b/c", "file.txt"); String contentId = ContentIdUtil.getContentId(file, watchDir, prefix); Assert.assertEquals(prefix + "b/c/file.txt", contentId); contentId = ContentIdUtil.getContentId(file, null, prefix); Assert.assertEquals(prefix + "file.txt", contentId); }