Redirector { public void doRedirect(HttpServletRequest request, HttpServletResponse response, String path) throws IOException { String redirectUrl = ""; String scheme = request.getServletContext().getInitParameter("scheme"); if (scheme != null) { redirectUrl = scheme + ": } redirectUrl += request.getContextPath() + applicationContextPath + path; response.sendRedirect(redirectUrl); }  void doRedirect(HttpServletRequest request, HttpServletResponse response, String path); void doForward(HttpServletRequest request, HttpServletResponse response, String path); void setApplicationContextPath(String applicationContextPath);  }
@Test public void shouldRedirectToRelativeUrlByDefault() throws Exception { when(servletContext.getInitParameter("scheme")).thenReturn(null); redirector.doRedirect(request, response, "/path"); verify(response).sendRedirect("/context-path/application-context-path/path"); }
@Test public void shouldRedirectToAbsoluteUrlWhenSchemeIsConfigured() throws Exception { when(servletContext.getInitParameter("scheme")).thenReturn("https"); redirector.doRedirect(request, response, "/path"); verify(response).sendRedirect("https: }