### Question:
Path implements Iterable<String>, Serializable { public boolean isCanonical() { int offset = 0; boolean text = false; if (path.equals(".")) { return true; } if (!isRoot() && path.endsWith("/")) { return false; } while (offset < path.length()) { String sub = path.substring(offset); if (sub.equals("/") || sub.equals("")) { break; } if (sub.startsWith("./") || sub.equals(".")) { return false; } boolean up = sub.startsWith("../") || sub.equals(".."); if (text && up) { return false; } if (up == false) { text = true; } int next = sub.indexOf("/"); if (next == -1) { break; } else if (next == 0 && offset != 0) { return false; } else { offset += next + 1; } } return true; } Path(String path);  Path(String path, boolean canonize); Path canonical(); boolean isCanonical(); boolean isRoot(); boolean isAbsolute(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); Iterator<String> iterator(); String getName(); boolean isAncestorOf(Path other); boolean isDescendantOf(Path other); boolean isParentOf(Path other); boolean isChildOf(Path other); int size(); Path parent(); String part(int index); Path subpath(int idx); Path toAbsolute(); Path append(Path relative); Path toRelative(Path ancestor); static final Path ROOT; static final Comparator<Path> SMALLEST_FIRST_COMPARATOR; static final Comparator<Path> LARGEST_FIRST_COMPARATOR; }### Answer:
@Test public void isCannonical() { assertTrue(new Path("/", false).isCanonical()); assertTrue(new Path("a", false).isCanonical()); assertTrue(new Path("a/b", false).isCanonical()); assertTrue(new Path("a/b/c", false).isCanonical()); assertTrue(new Path("a/..b/c", false).isCanonical()); assertTrue(new Path("a/b/c..", false).isCanonical()); assertTrue(new Path("..", false).isCanonical()); assertTrue(new Path("../", false).isCanonical()); assertTrue(new Path("../..", false).isCanonical()); assertTrue(new Path("../../", false).isCanonical()); assertTrue(new Path("../a", false).isCanonical()); assertTrue(new Path(".", false).isCanonical()); assertTrue(!new Path("./.", false).isCanonical()); assertTrue(!new Path("a assertTrue(!new Path("a/b/c assertTrue(!new Path("/.", false).isCanonical()); assertTrue(!new Path("./a", false).isCanonical()); assertTrue(!new Path("a/.", false).isCanonical()); assertTrue(!new Path("a/./b", false).isCanonical()); assertTrue(!new Path("./a/b/c", false).isCanonical()); assertTrue(!new Path("a/..b/./c", false).isCanonical()); assertTrue(!new Path("a/b/c../.", false).isCanonical()); assertTrue(!new Path("./..", false).isCanonical()); assertTrue(!new Path(".././", false).isCanonical()); assertTrue(!new Path(".././..", false).isCanonical()); assertTrue(!new Path("../.././", false).isCanonical()); assertTrue(!new Path("./../a", false).isCanonical()); assertTrue(!new Path("/..", false).isCanonical()); assertTrue(!new Path("/../..", false).isCanonical()); assertTrue(!new Path("a/..", false).isCanonical()); assertTrue(!new Path("a/../", false).isCanonical()); assertTrue(!new Path("../a/..", false).isCanonical()); assertTrue(!new Path("../../a/..", false).isCanonical()); assertTrue(!new Path("../../../a/..", false).isCanonical()); }