### Question:
SplitUrl { public static SplitUrl split(String url) { String trim = CodepointMatcher.ASCII_WHITESPACE.trim(url); if (trim.isEmpty()) { return SplitUrl.builder() .path("") .urlType(Type.PATH_RELATIVE) .build(); } Builder builder; if (CodepointMatcher.ALPHA.matches(trim.charAt(0))) { builder = fullUrlOrRelativePath(trim); } else if (slash.matches(trim.charAt(0))) { if (trim.length() == 2 && slash.matches(trim.charAt(1))) { return SplitUrl.builder() .urlType(Type.PROTOCOL_RELATIVE) .build(); } else if (trim.length() > 1 && slash.matches(trim.charAt(1))) { builder = authority(trim, 0).urlType(Type.PROTOCOL_RELATIVE); } else { builder = path(trim, 0).urlType(Type.PATH_ABSOLUTE); } } else if (trim.charAt(0) == '#') { builder = fragment(trim, 0).urlType(Type.FRAGMENT); } else { builder = path(trim, 0).urlType(Type.PATH_RELATIVE); } return builder.build(); }  @Nullable abstract String scheme(); @Nullable abstract String authority(); @Nullable abstract String path(); @Nullable abstract String query(); @Nullable abstract String fragment(); @Nullable abstract Type urlType(); static SplitUrl split(String url);  }### Answer:
@Test public void length1() { assertEquals(onlyPath("/"), SplitUrl.split("/")); assertEquals(onlyPath("p"), SplitUrl.split("p")); assertEquals(onlyPath(":"), SplitUrl.split(":")); assertEquals(onlyQuery(""), SplitUrl.split("?")); assertEquals(onlyFragment(""), SplitUrl.split("#")); }
@Test public void invalidOrMissingScheme() { assertEquals(onlyPath(":host"), SplitUrl.split(":host")); assertEquals(onlyPath("bad@scheme: assertEquals(onlyPath(": }
@Test public void onlyScheme() { try { SplitUrl.split("http:"); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage(), containsString("missing host")); } }
@Test public void onlyPath() { assertEquals(onlyPath(""), SplitUrl.split("")); assertEquals(onlyPath("/"), SplitUrl.split("/")); assertEquals(onlyPath("/"), SplitUrl.split("/")); assertEquals(onlyPath("a"), SplitUrl.split("a")); assertEquals(onlyPath("/a"), SplitUrl.split("/a")); assertEquals(onlyPath("/a/"), SplitUrl.split("/a/")); }
@Test public void onlyQuery() { assertEquals(onlyQuery(""), SplitUrl.split("?")); assertEquals(onlyQuery("?"), SplitUrl.split("??")); assertEquals(onlyQuery("/path"), SplitUrl.split("?/path")); assertEquals(onlyQuery("http: }
@Test public void onlyFragment() { assertEquals(onlyFragment(""), SplitUrl.split("#")); assertEquals(onlyFragment("/path"), SplitUrl.split("#/path")); assertEquals(onlyFragment("?query"), SplitUrl.split("#?query")); }