DefaultLogicResult implements LogicResult { public <T> T redirectTo(final Class<T> type) { logger.debug("redirecting to class {}", type.getSimpleName()); return proxifier.proxify(type, new MethodInvocation<T>() { public Object intercept(T proxy, Method method, Object[] args, SuperMethod superMethod) { if (!acceptsHttpGet(method)) { throw new IllegalArgumentException( "Your logic method must accept HTTP GET method if you want to redirect to it"); } try { String path = request.getContextPath(); String url = router.urlFor(type, method, args); includeParametersInFlash(type, method, args); path = path + url; logger.debug("redirecting to {}", path); response.sendRedirect(path); return null; } catch (IOException e) { throw new ProxyInvocationException(e); } } }); } @Inject  DefaultLogicResult(Proxifier proxifier, Router router, MutableRequest request, MutableResponse response,
			Container container, PathResolver resolver, TypeNameExtractor extractor, FlashScope flash, MethodInfo methodInfo); T forwardTo(final Class<T> type); T redirectTo(final Class<T> type);  }
@Test public void shouldPutParametersOnFlashScopeOnRedirect() throws Exception { logicResult.redirectTo(MyComponent.class).withParameter("a"); verify(flash).includeParameters(any(ResourceMethod.class), eq(new Object[] {"a"})); }
@Test public void shouldNotPutParametersOnFlashScopeOnRedirectIfThereAreNoParameters() throws Exception { logicResult.redirectTo(MyComponent.class).base(); verify(flash, never()).includeParameters(any(ResourceMethod.class), any(Object[].class)); }
@Test public void clientRedirectingWillRedirectToTranslatedUrl() throws NoSuchMethodException, IOException { final String url = "custom_url"; when(request.getContextPath()).thenReturn("/context"); when(router.urlFor(MyComponent.class, MyComponent.class.getDeclaredMethod("base"))).thenReturn(url); logicResult.redirectTo(MyComponent.class).base(); verify(response).sendRedirect("/context" + url); }
@Test public void canRedirectWhenLogicMethodIsNotAnnotatedWithHttpMethods() throws Exception { logicResult.redirectTo(MyComponent.class).base(); verify(response).sendRedirect(any(String.class)); }
@Test public void canRedirectWhenLogicMethodIsAnnotatedWithHttpGetMethod() throws Exception { logicResult.redirectTo(MyComponent.class).annotatedWithGet(); verify(response).sendRedirect(any(String.class)); }
@Test public void cannotRedirectWhenLogicMethodIsAnnotatedWithAnyHttpMethodButGet() throws Exception { try { logicResult.redirectTo(MyComponent.class).annotated(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { verify(response, never()).sendRedirect(any(String.class)); } }