### Question:
XWikiAuthServiceImpl extends AbstractXWikiAuthService { protected String stripContextPathFromURL(URL url, XWikiContext context) { String contextPath = context.getWiki().getWebAppPath(context); if (contextPath.endsWith("/") && !contextPath.startsWith("/")) { contextPath = "/" + StringUtils.chop(contextPath); } else if ("/".equals(contextPath)) { contextPath = ""; } String urlPrefix = url.getProtocol() + ": String encodedUrlPrefix = context.getResponse().encodeURL(urlPrefix); encodedUrlPrefix = encodedUrlPrefix.replaceAll(";jsessionid=.*?(?=\\?|$)", ""); encodedUrlPrefix = StringUtils.substringBeforeLast(encodedUrlPrefix, "?"); String strippedURL = StringUtils.removeStart(url.toExternalForm(), encodedUrlPrefix); if (!strippedURL.startsWith("/")) { strippedURL = "/" + strippedURL; } return strippedURL; }  @Override XWikiUser checkAuth(XWikiContext context); @Override XWikiUser checkAuth(String username, String password, String rememberme, XWikiContext context); @Override void showLogin(XWikiContext context); @Override Principal authenticate(String username, String password, XWikiContext context);  }### Answer:
@Test public void testStripContextPathFromURLWithSlashAfter() throws Exception { doReturn("xwiki/").when(this.oldcore.getSpyXWiki()).getWebAppPath(any(XWikiContext.class)); assertEquals("/something", this.authService .stripContextPathFromURL(new URL("http: }
@Test public void testStripContextPathFromURLWhenRootContextPathWithSlash() throws Exception { doReturn("/").when(this.oldcore.getSpyXWiki()).getWebAppPath(any(XWikiContext.class)); assertEquals("/something", this.authService.stripContextPathFromURL(new URL("http: this.oldcore.getXWikiContext())); }
@Test public void testStripContextPathFromURLWhenRootContextPathWithoutSlash() throws Exception { doReturn("").when(this.oldcore.getSpyXWiki()).getWebAppPath(any(XWikiContext.class)); assertEquals("/something", this.authService.stripContextPathFromURL(new URL("http: this.oldcore.getXWikiContext())); }
@Test public void testStripContextPathFromURLWhenOutBoundRewriteRuleChangingContextPath() throws Exception { doReturn("xwiki/").when(this.oldcore.getSpyXWiki()).getWebAppPath(any(XWikiContext.class)); XWikiResponse xwikiResponse = mock(XWikiResponse.class); when(xwikiResponse.encodeURL(any())) .thenReturn("http: this.oldcore.getXWikiContext().setResponse(xwikiResponse); assertEquals("/something", this.authService.stripContextPathFromURL( new URL("http: }
@Test public void testStripContextPathFromURLWithSlashBefore() throws Exception { doReturn("xwiki/").when(this.oldcore.getSpyXWiki()).getWebAppPath(any(XWikiContext.class)); assertEquals("/something", this.authService .stripContextPathFromURL(new URL("http: }
@Test public void testStripContextPathFromURLWhenRootWebAppAndJSessionId() throws Exception { doReturn("").when(this.oldcore.getSpyXWiki()).getWebAppPath(any(XWikiContext.class)); XWikiResponse xwikiResponse = mock(XWikiResponse.class); when(xwikiResponse.encodeURL("http: .thenReturn("http: this.oldcore.getXWikiContext().setResponse(xwikiResponse); assertEquals("/something", this.authService.stripContextPathFromURL(new URL("http: this.oldcore.getXWikiContext())); }