### Question:
HttpUriParser implements UriParser { @Override public int linkifyUri(String text, int startPos, StringBuffer outputBuffer) { int currentPos = startPos; String shortScheme = text.substring(currentPos, Math.min(currentPos + 7, text.length())); String longScheme = text.substring(currentPos, Math.min(currentPos + 8, text.length())); if (longScheme.equalsIgnoreCase("https: currentPos += "https: } else if (shortScheme.equalsIgnoreCase("http: currentPos += "http: } else if (shortScheme.equalsIgnoreCase("rtsp: currentPos += "rtsp: } else { return startPos; } int matchedAuthorityEnd = tryMatchAuthority(text, currentPos); if (matchedAuthorityEnd == currentPos) { return startPos; } currentPos = matchedAuthorityEnd; if (currentPos < text.length() && text.charAt(currentPos) == '/') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, "/:@"); } if (currentPos < text.length() && text.charAt(currentPos) == '?') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } if (currentPos < text.length() && text.charAt(currentPos) == '#') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } String httpUri = text.substring(startPos, currentPos); outputBuffer.append("<a href=\"") .append(httpUri) .append("\">") .append(httpUri) .append("</a>"); return currentPos; }  @Override int linkifyUri(String text, int startPos, StringBuffer outputBuffer);  }### Answer:
@Test public void domainWithTrailingSpace() { String text = "http: int endPos = parser.linkifyUri(text, 0, outputBuffer); assertLinkOnly("http: assertEquals(text.length() - 1, endPos); }
@Test public void domainWithTrailingNewline() { String text = "http: int endPos = parser.linkifyUri(text, 0, outputBuffer); assertLinkOnly("http: assertEquals(text.length() - 1, endPos); }
@Test public void domainWithTrailingAngleBracket() { String text = "<http: int endPos = parser.linkifyUri(text, 1, outputBuffer); assertLinkOnly("http: assertEquals(text.length() - 1, endPos); }
@Test public void uriInMiddleAfterInput() { String prefix = "prefix "; String uri = "http: String text = prefix + uri; parser.linkifyUri(text, prefix.length(), outputBuffer); assertLinkOnly(uri, outputBuffer); }
@Test public void uriInMiddleOfInput() { String prefix = "prefix "; String uri = "http: String postfix = " postfix"; String text = prefix + uri + postfix; parser.linkifyUri(text, prefix.length(), outputBuffer); assertLinkOnly(uri, outputBuffer); }