ResetController { @RequestMapping(value = "/forgotreset", method = RequestMethod.POST) @ResponseBody public ResetViewData reset(@RequestBody ResetForm form, final HttpServletRequest request) { ResetViewData viewData = new ResetViewData(); viewData.setResetForm(form); viewData.setPageLang(cookieLocaleResolver.resolveLocale(request)); viewData.setInvalidToken(false); List<String> errors = resetFormValidator.validate(form); if (!errors.isEmpty()) { viewData.setResetSucceed(false); viewData.setErrors(errors); return viewData; } else { try { recoveryService.resetPassword(form.getToken(), form.getPassword(), form.getPasswordConfirmation()); } catch (InvalidTokenException e) { LOGGER.debug("Reset with invalid token attempted", e); errors.add("server.reset.invalidToken"); viewData.setInvalidToken(true); } catch (RuntimeException e) { LOGGER.error("Error while reseting passsword", e); errors.add("server.reset.error"); } viewData.setResetSucceed(true); viewData.setErrors(errors); } return viewData; }  @RequestMapping(value = "/changepassword", method = RequestMethod.GET) ModelAndView changePasswordView(HttpServletRequest request); @RequestMapping(value = "/changepassword", method = RequestMethod.POST) @ResponseBody ChangePasswordViewData changePassword(@RequestBody ChangePasswordForm form); @RequestMapping(value = "/forgotreset", method = RequestMethod.GET) ModelAndView resetView(HttpServletRequest request); @RequestMapping(value = "/forgotresetviewdata", method = RequestMethod.GET) @ResponseBody ResetViewData getResetViewData(final HttpServletRequest request); @RequestMapping(value = "/forgotreset", method = RequestMethod.POST) @ResponseBody ResetViewData reset(@RequestBody ResetForm form, final HttpServletRequest request);  }
@Test public void testReset() throws Exception { ResetViewData expected = getResetViewData(false, true, new ArrayList<String>(), getResetForm(TOKEN, PASSWORD, PASSWORD)); controller.perform(post("/forgotreset") .locale(Locale.ENGLISH) .body(new ObjectMapper().writeValueAsBytes(getResetForm(TOKEN, PASSWORD, PASSWORD))) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().string(new ObjectMapper().writeValueAsString(expected))); verify(recoveryService).resetPassword(TOKEN, PASSWORD, PASSWORD); }