InMemoryPath implements Path { @Override public Path normalize() { return new InMemoryPath(normalizeModel(pathElements)); } private  InMemoryPath(final List<String> pathElements);  InMemoryPath(final String relativePath); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString(); @Override Path getParent(); @Override Path normalize(); @Override Path resolve(Path other); @Override Path resolve(String other); @Override Path getFileName(); @Override URI toUri(); @Override Path relativize(Path other); @Override Path resolveSibling(Path other); @Override Path resolveSibling(String other); @Override Iterator<Path> iterator(); @Override Path getName(int index); @Override FileSystem getFileSystem(); @Override Path toAbsolutePath(); @Override Path toRealPath(LinkOption... options); @Override File toFile(); @Override WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers); @Override WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events); @Override int compareTo(Path other); @Override boolean isAbsolute(); @Override Path getRoot(); @Override int getNameCount(); @Override Path subpath(int beginIndex, int endIndex); @Override boolean startsWith(Path other); @Override boolean startsWith(String other); @Override boolean endsWith(Path other); @Override boolean endsWith(String other);  }
@Test public void normalize() { final InMemoryPath path = new InMemoryPath("././less/./../less/hpe-elements/../static/../main"); assertEquals(new InMemoryPath("less/main"), path.normalize()); }
@Test public void normalizeThrowsIfTraversalBeyondRoot() { final InMemoryPath path = new InMemoryPath("./less/../../main"); try { path.normalize(); fail("Expected exception to have been thrown"); } catch(final IllegalArgumentException e) { assertThat("Exception has the correct message", e.getMessage(), containsString("Path contains illegal traversal")); } }