### Question:
PathUtil { public static final Path resolveSecurely(Path rootPath, String path) { Path resolvedPath; if(path == null || path.isEmpty()) { resolvedPath = rootPath.normalize(); } else { String relativePath = removeSuperflousSlashes(path); resolvedPath = rootPath.resolve(relativePath).normalize(); } if(!resolvedPath.startsWith(rootPath)) { throw DeploymentRepositoryLogger.ROOT_LOGGER.forbiddenPath(path); } return resolvedPath; }  static void copyRecursively(final Path source, final Path target, boolean overwrite); static void deleteSilentlyRecursively(final Path path); static void deleteRecursively(final Path path); static final Path resolveSecurely(Path rootPath, String path); static final boolean isArchive(Path path); static final boolean isArchive(InputStream in); static List<ContentRepositoryElement> listFiles(final Path rootPath, Path tempDir, final ContentFilter filter); static Path createTempDirectory(Path dir, String prefix); static void unzip(Path zip, Path target); static String getFileExtension(Path path); static Path readFile(Path src, Path tempDir);  }### Answer:
@Test public void testResolveSecurely() throws Exception { Path result = PathUtil.resolveSecurely(root, "../pathutil/test"); Assert.assertEquals(root.resolve("test"), result); try { PathUtil.resolveSecurely(root, "../test"); Assert.fail("We shouldn't be able to go out"); } catch (IllegalArgumentException ioex) { Assert.assertTrue(ioex.getMessage().contains("WFLYDR0013")); } try { PathUtil.resolveSecurely(root, "test/../../test"); Assert.fail("We shouldn't be able to go out"); } catch (IllegalArgumentException ioex) { Assert.assertTrue(ioex.getMessage().contains("WFLYDR0013")); } result = PathUtil.resolveSecurely(root, "/index.html"); Assert.assertEquals(root.resolve("index.html"), result); result = PathUtil.resolveSecurely(root, " Assert.assertEquals(root.resolve("index.html"), result); }