### Question:
LinkNormalizer { public String normalize(String original, String extracted) { Validate.notBlank(original); Validate.notNull(extracted); URI originalUri = null; URI extractedUri = null; try { originalUri = new URI(original); extractedUri = new URI(extracted); } catch (URISyntaxException ex) { logger.warn("Extracted URI is invalid: " + extracted, ex); return null; } UriBuilder retval = UriBuilder.fromUri(extractedUri); boolean hasHost = StringUtils.isNotBlank(extractedUri.getHost()); boolean hasScheme = StringUtils.isNotBlank(extractedUri.getScheme()); if (!hasScheme) { retval.scheme(originalUri.getScheme()); } if (!hasHost) { retval.host(originalUri.getHost()); String normalizedPath = normalizePath(originalUri.getPath(), extractedUri.getPath()); retval.replacePath(normalizedPath); } retval.fragment(""); return retval.toString(); }  String normalize(String original, String extracted);  }### Answer:
@SuppressWarnings("ConstantConditions") @Test(expected = NullPointerException.class) public void normalize_originalIsNull_throwsNullPointerException() { String original = null; String extracted = "http: String output = linkNormalizer.normalize(original, extracted); assertEquals(extracted, output); }
@Test public void normalize_extractedContainsRelativePathWithDirectoryChangeAndOriginalIsDirectory_directoryChanged() { String original = "http: String extracted = "../quux"; String output = linkNormalizer.normalize(original, extracted); assertEquals("http: }
@Test public void normalize_extractedContainsRelativePathWithExtraDirectoryChange_directoryChangedButStops() { String original = "http: String extracted = "../../quux"; String output = linkNormalizer.normalize(original, extracted); assertEquals("http: }
@SuppressWarnings("ConstantConditions") @Test(expected = NullPointerException.class) public void normalize_extractedIsNull_throwsNullPointerException() { String original = "http: String extracted = null; String output = linkNormalizer.normalize(original, extracted); }
@Test(expected = IllegalArgumentException.class) public void normalize_originalIsBlank_throwsIllegalArgumentException() { String original = ""; String extracted = "http: String output = linkNormalizer.normalize(original, extracted); }
@Test public void normalize_extractedIsBadURI_returnsNull() { String original = "http: String extracted = "ij><g8o.hp(<G^F*"; String output = linkNormalizer.normalize(original, extracted); assertNull(output); }
@Test public void normalize_extractedIsFullURI_noChange() { String original = "http: String extracted = "http: String output = linkNormalizer.normalize(original, extracted); }
@Test public void normalize_extractedIsPathOnly_addsSchemeAndHost() { String original = "http: String extracted = "/quux"; String output = linkNormalizer.normalize(original, extracted); assertEquals("http: }
@Test public void normalize_extractedIsPathOnlyNoSlash_addsSchemeAndHost() { String original = "http: String extracted = "quux"; String output = linkNormalizer.normalize(original, extracted); assertEquals("http: }
@Test public void normalize_extractedIsProtocolRelative_addsScheme() { String original = "http: String extracted = " String output = linkNormalizer.normalize(original, extracted); assertEquals("http: }
@Test public void normalize_extractedIsFullURIWithBadPath_noChange() { String original = "http: String extracted = "http: String output = linkNormalizer.normalize(original, extracted); assertEquals(extracted, output); }
@Test public void normalize_extractedContainsRelativePathWithDirectoryChange_directoryChanged() { String original = "http: String extracted = "../quux"; String output = linkNormalizer.normalize(original, extracted); assertEquals("http: }