UriUtil { public static String getRelativeUri(String completeUri) { int offset = 0; if (completeUri.startsWith("http: offset = 7; } if (completeUri.startsWith("https: offset = 8; } if (completeUri.startsWith("ws: offset = 5; } if (completeUri.startsWith("wss: offset = 6; } int slashIndex = completeUri.indexOf("/", offset); int paramIndex = completeUri.indexOf("?", offset); if (paramIndex != -1 && paramIndex < slashIndex) { return "/" + completeUri.substring(paramIndex); } if (slashIndex != -1) { return completeUri.substring(slashIndex); } if (paramIndex != -1) { return "/" + completeUri.substring(paramIndex); } return "/"; }  static String getUriWithParameters(String uri, List<Param> parameters); static String getRelativeUri(String completeUri);  }
@Test public void noPath() throws Exception { String relativeUri = UriUtil.getRelativeUri("http: assertEquals("/", relativeUri); }
@Test public void simplePath() throws Exception { String relativeUri = UriUtil.getRelativeUri("http: assertEquals("/hello", relativeUri); }
@Test public void simplePath2() throws Exception { String relativeUri = UriUtil.getRelativeUri("http: assertEquals("/hello/world", relativeUri); }
@Test public void simplePathWithArguments() throws Exception { String relativeUri = UriUtil.getRelativeUri("http: assertEquals("/hello?world", relativeUri); }
@Test public void noPathWithArgument() throws Exception { String relativeUri = UriUtil.getRelativeUri("http: assertEquals("/?world", relativeUri); }
@Test public void noPathWithArgument2() throws Exception { String relativeUri = UriUtil.getRelativeUri("http: assertEquals("/?world", relativeUri); }
@Test public void noPathWithArgument3() throws Exception { String relativeUri = UriUtil.getRelativeUri("http: assertEquals("/?hello/world", relativeUri); }