### Question:
LogoutServlet extends HttpServlet { protected String sanitizeLoginPageUrl(final String loginURL) { return new RedirectUrlBuilder(new URLProtector().protectRedirectUrl(loginURL)).build().getUrl(); }    }### Answer:
@Test public void testtSanitizeLoginPageUrlEmptyLoginPageUrl() throws Exception { String loginPage = logoutServlet.sanitizeLoginPageUrl(""); assertThat(loginPage).isEqualToIgnoringCase(""); }
@Test public void testtSanitizeLoginPageUrlFromMaliciousRedirectShouldReturnBrokenUrl() throws Exception { try { logoutServlet.sanitizeLoginPageUrl("http: fail("building a login page with a different host on the redirectURL should fail"); } catch (Exception e) { if (!(e.getCause() instanceof URISyntaxException)) { fail("Exception root cause should be a URISyntaxException"); } } }
@Test public void testtSanitizeLoginPageUrlFromMaliciousRedirectShouldReturnBrokenUrl2() throws Exception { String loginPage = logoutServlet.sanitizeLoginPageUrl("test.com"); assertThat(loginPage).isEqualToIgnoringCase("test.com"); }
@Test public void testSanitizeLoginPageUrlShouldReturnCorrectUrl() throws Exception { String loginPage = logoutServlet.sanitizeLoginPageUrl("portal/homepage?p=test#poutpout"); assertThat(loginPage).isEqualToIgnoringCase("portal/homepage?p=test#poutpout"); }