UriUtils { public static List<String> parseSegments(String uri) { try { List<String> segments = new ArrayList<>(); String path = parsePath(uri); if (path != null) { for (String segment : path.split("/")) { if (segment.length() > 0) segments.add(URLDecoder.decode(segment, "UTF-8")); } } return segments; } catch (UnsupportedEncodingException e) { throw new AssertionError(); } } private  UriUtils(); static List<String> parseSegments(String uri); static List<InetSocketAddress> parseInetSocketAddresses(String uri); static List<InetSocketAddress> parseInetSocketAddresses(String uri, int defaultPort); static String parseScheme(String uri); static String parseAuthority(String uri); static String parseUserInfo(String uri); static String parsePath(String uri); static String parseQuery(String uri); static String appendSegmentToPath(String path, String segment);  }
@Test public void testParseSegments_emptyPath() { String input = "scheme: List<String> pathSegements = UriUtils.parseSegments(input); assertThat(input, pathSegements.size(), is(0)); }
@Test public void testParseSegments_ok_1() { String input = "/path/to/resource?simulation-freq=10&max-servers=2&timeout=2"; List<String> pathSegements = UriUtils.parseSegments(input); assertThat(input, pathSegements, hasItems("path", "to", "resource")); }
@Test public void testParseSegments_ok_2() { String input = "scheme: List<String> pathSegements = UriUtils.parseSegments(input); assertThat(input, pathSegements, hasItems("path", "to", "resource")); }
@Test public void testParseSegments_ok_3() { String input = "scheme: List<String> pathSegements = UriUtils.parseSegments(input); assertThat(input, pathSegements, hasItems("some", "path")); }