FileBrowserService { public String decodeDirectoryUrl(String url, String rootDirectory) { String directory; try { directory = URLDecoder.decode(url, Citrus.CITRUS_FILE_ENCODING); } catch (UnsupportedEncodingException e) { throw new ApplicationRuntimeException("Unable to decode directory URL", e); } if (directory.equals("/")) { if (StringUtils.hasText(rootDirectory)) { directory = rootDirectory; } else { return ""; } } if (!StringUtils.hasText(directory)) { return ""; } else if (directory.charAt(directory.length() - 1) == WINDOWS_SEPARATOR) { directory = directory.substring(0, directory.length() - 1) + "/"; } else if (directory.charAt(directory.length() - 1) != UNIX_SEPARATOR) { directory += "/"; } return directory; }  String[] getFolders(File directory); File findFileInPath(File directory, String filename, boolean recursive); String decodeDirectoryUrl(String url, String rootDirectory); String separatorsToSystem(String path); String separatorsToWindows(String path); String separatorsToUnix(String path);  }
@Test public void testDecodeDirectoryUrl() throws Exception { String path = testling.decodeDirectoryUrl(URLEncoder.encode("/request/test/1", Citrus.CITRUS_FILE_ENCODING), ""); Assert.assertEquals(path, "/request/test/1/"); path = testling.decodeDirectoryUrl(URLEncoder.encode("/request/test/1", Citrus.CITRUS_FILE_ENCODING), "/Users/home"); Assert.assertEquals(path, "/request/test/1/"); path = testling.decodeDirectoryUrl(URLEncoder.encode("/", Citrus.CITRUS_FILE_ENCODING), "/Users/home"); Assert.assertEquals(path, "/Users/home/"); path = testling.decodeDirectoryUrl(URLEncoder.encode("", Citrus.CITRUS_FILE_ENCODING), "/Users/home"); Assert.assertEquals(path, ""); path = testling.decodeDirectoryUrl(URLEncoder.encode("/", Citrus.CITRUS_FILE_ENCODING), ""); Assert.assertEquals(path, ""); }