### Question:
CustomPageRequestModifier { public void redirectToValidPageUrl(final HttpServletRequest request, final HttpServletResponse response) throws IOException { final StringBuilder taskURLBuilder = new StringBuilder(request.getContextPath()); taskURLBuilder.append(request.getServletPath()) .append(request.getPathInfo()) .append("/"); if(!StringUtil.isBlank(request.getQueryString())){ taskURLBuilder.append("?").append(request.getQueryString()); } response.sendRedirect(response.encodeRedirectURL(taskURLBuilder.toString())); }  void redirectToValidPageUrl(final HttpServletRequest request, final HttpServletResponse response); void forwardIfRequestIsAuthorized(final HttpServletRequest request, final HttpServletResponse response, final String apiPathShouldStartWith, final String apiPath);  }### Answer:
@Test public void redirect_with_trailing_slash_should_not_encode_parameter() throws Exception { when(request.getContextPath()).thenReturn("bonita/"); when(request.getServletPath()).thenReturn("apps/"); when(request.getPathInfo()).thenReturn("myapp/mypage"); when(request.getQueryString()).thenReturn("time=12:00"); when(response.encodeRedirectURL("bonita/apps/myapp/mypage/?time=12:00")).thenReturn("bonita/apps/myapp/mypage/?time=12:00"); CustomPageRequestModifier customPageRequestModifier = new CustomPageRequestModifier(); customPageRequestModifier.redirectToValidPageUrl(request, response); verify(response).sendRedirect("bonita/apps/myapp/mypage/?time=12:00"); }
@Test public void redirect_with_trailing_slash_should_not_add_question_mark() throws Exception { when(request.getContextPath()).thenReturn("bonita/"); when(request.getServletPath()).thenReturn("apps/"); when(request.getPathInfo()).thenReturn("myapp/mypage"); when(response.encodeRedirectURL("bonita/apps/myapp/mypage/")).thenReturn("bonita/apps/myapp/mypage/"); CustomPageRequestModifier customPageRequestModifier = new CustomPageRequestModifier(); customPageRequestModifier.redirectToValidPageUrl(request, response); verify(response).sendRedirect("bonita/apps/myapp/mypage/"); }