HttpUtils { public static URI appendTrailingSlash(URI uri) { String uriString = uri.toString(); if (uriString.matches(".*/$")) { return uri; } else return URI.create(uriString + "/"); } private  HttpUtils(); static String readUrl(URL url, String charsetName); static URI appendTrailingSlash(URI uri); static URI getSanitizedPath(UriInfo uriInfo); static URI getDirectoryURI(UriInfo uriInfo);  }
@Test public void testAppendTrailingSlash() { URI withTrailingSlash = URI.create("http: URI withoutTrailingSlash = URI.create("http: URI resultUnchanged = HttpUtils.appendTrailingSlash(withTrailingSlash); URI resultSlashAdded = HttpUtils.appendTrailingSlash(withoutTrailingSlash); Assert.assertEquals(withTrailingSlash, resultUnchanged); Assert.assertEquals(withTrailingSlash, resultSlashAdded); }