### Question:
UrlSplitter { public UrlParts split(String url) { Matcher matcher = URL_PATTERN.matcher(url.trim()); if (matcher.matches()) { UrlParts parts = new UrlParts(); parts.scheme = matcher.group(1); parts.host = matcher.group(2); parts.port = matcher.group(3); parts.path = matcher.group(4); parts.query = matcher.group(5); return parts; } return null; }  UrlParts split(String url);  }### Answer:
@Test public void testSplit1() { UrlSplitter.UrlParts parts = splitter.split("http: Assert.assertEquals("http: Assert.assertEquals("example.com", parts.getHost()); Assert.assertEquals(":8080", parts.getPort()); Assert.assertEquals("/path/here", parts.getPath()); Assert.assertEquals("?param=1", parts.getQuery()); }
@Test public void testSplit2() { UrlSplitter.UrlParts parts = splitter.split("http: Assert.assertEquals("http: Assert.assertEquals("example.com", parts.getHost()); Assert.assertNull(parts.getPort()); Assert.assertNull(parts.getPath()); Assert.assertEquals("?param=1", parts.getQuery()); }
@Test public void testSplit3() { UrlSplitter.UrlParts parts = splitter.split("http: Assert.assertEquals("http: Assert.assertEquals("example.com", parts.getHost()); Assert.assertNull(parts.getPort()); Assert.assertEquals("/path/1/", parts.getPath()); Assert.assertNull(parts.getQuery()); }