DefaultPageResult implements PageResult { public void redirectTo(String url) { logger.debug("redirection to {}", url); try { if (url.startsWith("/")) { response.sendRedirect(request.getContextPath() + url); } else { response.sendRedirect(url); } } catch (IOException e) { throw new ResultException(e); } } @Inject  DefaultPageResult(MutableRequest req, MutableResponse res, MethodInfo requestInfo,
			PathResolver resolver, Proxifier proxifier); void defaultView(); void include(); void redirectTo(String url); void forwardTo(String url); T of(final Class<T> controllerType); void redirect(String url); void forward(String url); void forward();  }
@Test public void shouldRedirectIncludingContext() throws Exception { when(request.getContextPath()).thenReturn("/context"); view.redirectTo("/any/url"); verify(response).sendRedirect("/context/any/url"); }
@Test public void shouldNotIncludeContextPathIfURIIsAbsolute() throws Exception { view.redirectTo("http: verify(request, never()).getContextPath(); verify(response, only()).sendRedirect("http: }
@Test(expected = ResultException.class) public void shouldThrowResultExceptionIfIOExceptionOccursWhileRedirect() throws Exception { doThrow(new IOException()).when(response).sendRedirect(anyString()); view.redirectTo("/any/url"); }