@Test public void test_invalid_password_match() throws Exception { PasswordConfirmationException pe = new PasswordConfirmationException(messageCode, email); BadCredentialsException be = new BadCredentialsException("", pe); entryPoint.commence(request, response, be); verify(request, times(1)).getRequestDispatcher(eq("/reset_password")); verify(request, times(1)).setAttribute(eq("message_code"), eq(messageCode)); verify(requestDispatcher, timeout(1)).forward(any(HttpServletRequest.class), same(response)); verify(response, times(1)).setStatus(eq(HttpStatus.UNPROCESSABLE_ENTITY.value())); }
request.setAttribute("message_code", passwordConfirmationException.getMessageCode());
@Test public void invalid_password_confirmation() throws Exception { request.setParameter("password_confirmation", "invalid"); Exception e = error_during_password_reset(PasswordConfirmationException.class); assertTrue(e instanceof AuthenticationException); assertNotNull(e.getCause()); assertTrue(e.getCause() instanceof PasswordConfirmationException); PasswordConfirmationException pe = (PasswordConfirmationException)e.getCause(); assertEquals("form_error", pe.getMessageCode()); assertEquals(email, pe.getEmail()); }
public void throwIfNotValid() { if (!valid()) { throw new PasswordConfirmationException(getMessageCode(), getEmail()); } }