Paths { public static String removePrefix(final Path wholePath, final Path prefixToRemove) { PortablePreconditions.checkNotNull("prefixToRemove", prefixToRemove); PortablePreconditions.checkNotNull("wholePath", wholePath); if (prefixToRemove.toURI().length() > wholePath.toURI().length()) { throw new IllegalArgumentException("Prefix is longer than the URI where it is being removed from."); } final org.uberfire.java.nio.file.Path nioWholePath = convert(wholePath); final org.uberfire.java.nio.file.Path nioPrefixToRemove = convert(prefixToRemove); if (!nioWholePath.startsWith(nioPrefixToRemove)) { throw new IllegalArgumentException("The beginning of the whole Path " + nioWholePath + " does not match the prefix path " + nioPrefixToRemove + "."); } return nioPrefixToRemove.relativize(nioWholePath).toString(); }  static Path convert(final org.uberfire.java.nio.file.Path path); static org.uberfire.java.nio.file.Path convert(final Path path); static FileSystem convert(final org.uberfire.java.nio.file.FileSystem fs); static String readLockedBy(final Path path); static boolean isLock(final Path path); static String removePrefix(final Path wholePath,
                                      final Path prefixToRemove); static org.uberfire.java.nio.file.Path normalizePath(final org.uberfire.java.nio.file.Path path); static Path normalizePath(final Path path);  }
@Test public void getFilePathFromProjectRoot() throws Exception { final Path repositoryRoot = getPath("file: "/"); final Path pathToFile = getPath("file: "file.txt"); assertEquals("org/test/file.txt", Paths.removePrefix(pathToFile, repositoryRoot)); }
@Test public void getFilePath() throws Exception { final Path repositoryRoot = getPath("file: "test"); final Path pathToFile = getPath("file: "file.txt"); assertEquals("file.txt", Paths.removePrefix(pathToFile, repositoryRoot)); }
@Test public void pathsAreEqual() throws Exception { final Path repositoryRoot = getPath("file: "test"); assertEquals("", Paths.removePrefix(repositoryRoot, repositoryRoot)); }
@Test(expected = IllegalArgumentException.class) public void pathIsShorterThanPrefix() throws Exception { final Path repositoryRoot = getPath("file: "test"); final Path pathToFile = getPath("file: "file.txt"); Paths.removePrefix(repositoryRoot, pathToFile); }
@Test(expected = IllegalArgumentException.class) public void prefixDoesNotMatch() throws Exception { final Path repositoryRoot = getPath("file: "test"); final Path pathToFile = getPath("file: "file.txt"); Paths.removePrefix(pathToFile, repositoryRoot); }