Login implements Controller { protected static String removeErrorParameter(String redirect) { redirect = ERR_PARAM_NOT_ALONE_PATTERN.matcher(redirect).replaceAll("\\?"); redirect = ERR_PARAM_ALONE_PATTERN.matcher(redirect).replaceAll(""); redirect = ERR_PARAM_END_PATTERN.matcher(redirect).replaceAll(""); return redirect; }  static String getMapping(); static String getServletPath(); ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response);  }
@Test public void testRemoveErrorParameter() { final String baseUrl = "https: String url = baseUrl + "?loginError=tutu"; String result = Login.removeErrorParameter(url); Assert.assertEquals(baseUrl, result); url = baseUrl + "?loginError=tutu&tata=toto"; result = Login.removeErrorParameter(url); Assert.assertEquals(baseUrl + "?tata=toto", result); url = baseUrl + "?titi=tete&loginError=tutu&tata=toto"; result = Login.removeErrorParameter(url); Assert.assertEquals(baseUrl + "?titi=tete&tata=toto", result); url = baseUrl + "?titi=tete&tata=toto&loginError=tutu"; result = Login.removeErrorParameter(url); Assert.assertEquals(baseUrl + "?titi=tete&tata=toto", result); }