@Test public void testValidatePasswordsNotTheSame() { PasswordReset obj = new PasswordReset(); obj.setEmailAddress("test@test.com"); obj.setPassword("123456"); obj.setConfirmPassword("1234567"); Mockito.when(userDao.isRegisteredByEmail("test@test.com")).thenReturn(true); BindException error = new BindException(obj, "passwordReset"); changePasswordValidator.validate(obj, error); Mockito.verify(userDao).isRegisteredByEmail("test@test.com"); assertTrue(error.hasErrors()); assertEquals(1, error.getGlobalErrorCount()); ObjectError objError = error.getGlobalError(); assertNotNull(objError); assertEquals("err.your-password-confirmation-did-not-match-with-password", objError.getCode()); }
public void validate(Object clazz, Errors e) { PasswordReset obj = (PasswordReset) clazz; ValidationUtils.rejectIfEmptyOrWhitespace(e, "emailAddress", "error.required", new Object[]{"Email Address"}); if (!StringUtil.isEmpty(obj.getEmailAddress()) && !userDao.isRegisteredByEmail(obj.getEmailAddress())) { e.rejectValue("emailAddress","msg.email-address-is-not-registered", "Sorry, but your email address is not registered."); } ValidationUtils.rejectIfEmptyOrWhitespace(e, "password", "error.required", new Object[]{"Password"}); ValidationUtils.rejectIfEmptyOrWhitespace(e, "confirmPassword", "error.required", new Object[]{"Confirm Password"}); if (!StringUtil.isEmpty(obj.getPassword()) && (obj.getPassword().length()<6)) { e.reject("err.your-password-should-be-at-least-6-characters-long","Your password should be at least 6 characters long."); } if (!StringUtil.isEmpty(obj.getPassword()) && !StringUtil.isEmpty(obj.getConfirmPassword()) && !obj.getPassword().equals(obj.getConfirmPassword()) ) { e.reject("err.your-password-confirmation-did-not-match-with-password", "Your password confirmation did not match with password."); } }
ChangePasswordValidator implements Validator { public void validate(Object clazz, Errors e) { PasswordReset obj = (PasswordReset) clazz; ValidationUtils.rejectIfEmptyOrWhitespace(e, "emailAddress", "error.required", new Object[]{"Email Address"}); if (!StringUtil.isEmpty(obj.getEmailAddress()) && !userDao.isRegisteredByEmail(obj.getEmailAddress())) { e.rejectValue("emailAddress","msg.email-address-is-not-registered", "Sorry, but your email address is not registered."); } ValidationUtils.rejectIfEmptyOrWhitespace(e, "password", "error.required", new Object[]{"Password"}); ValidationUtils.rejectIfEmptyOrWhitespace(e, "confirmPassword", "error.required", new Object[]{"Confirm Password"}); if (!StringUtil.isEmpty(obj.getPassword()) && (obj.getPassword().length()<6)) { e.reject("err.your-password-should-be-at-least-6-characters-long","Your password should be at least 6 characters long."); } if (!StringUtil.isEmpty(obj.getPassword()) && !StringUtil.isEmpty(obj.getConfirmPassword()) && !obj.getPassword().equals(obj.getConfirmPassword()) ) { e.reject("err.your-password-confirmation-did-not-match-with-password", "Your password confirmation did not match with password."); } } }
ChangePasswordValidator implements Validator { public void validate(Object clazz, Errors e) { PasswordReset obj = (PasswordReset) clazz; ValidationUtils.rejectIfEmptyOrWhitespace(e, "emailAddress", "error.required", new Object[]{"Email Address"}); if (!StringUtil.isEmpty(obj.getEmailAddress()) && !userDao.isRegisteredByEmail(obj.getEmailAddress())) { e.rejectValue("emailAddress","msg.email-address-is-not-registered", "Sorry, but your email address is not registered."); } ValidationUtils.rejectIfEmptyOrWhitespace(e, "password", "error.required", new Object[]{"Password"}); ValidationUtils.rejectIfEmptyOrWhitespace(e, "confirmPassword", "error.required", new Object[]{"Confirm Password"}); if (!StringUtil.isEmpty(obj.getPassword()) && (obj.getPassword().length()<6)) { e.reject("err.your-password-should-be-at-least-6-characters-long","Your password should be at least 6 characters long."); } if (!StringUtil.isEmpty(obj.getPassword()) && !StringUtil.isEmpty(obj.getConfirmPassword()) && !obj.getPassword().equals(obj.getConfirmPassword()) ) { e.reject("err.your-password-confirmation-did-not-match-with-password", "Your password confirmation did not match with password."); } }  }
ChangePasswordValidator implements Validator { public void validate(Object clazz, Errors e) { PasswordReset obj = (PasswordReset) clazz; ValidationUtils.rejectIfEmptyOrWhitespace(e, "emailAddress", "error.required", new Object[]{"Email Address"}); if (!StringUtil.isEmpty(obj.getEmailAddress()) && !userDao.isRegisteredByEmail(obj.getEmailAddress())) { e.rejectValue("emailAddress","msg.email-address-is-not-registered", "Sorry, but your email address is not registered."); } ValidationUtils.rejectIfEmptyOrWhitespace(e, "password", "error.required", new Object[]{"Password"}); ValidationUtils.rejectIfEmptyOrWhitespace(e, "confirmPassword", "error.required", new Object[]{"Confirm Password"}); if (!StringUtil.isEmpty(obj.getPassword()) && (obj.getPassword().length()<6)) { e.reject("err.your-password-should-be-at-least-6-characters-long","Your password should be at least 6 characters long."); } if (!StringUtil.isEmpty(obj.getPassword()) && !StringUtil.isEmpty(obj.getConfirmPassword()) && !obj.getPassword().equals(obj.getConfirmPassword()) ) { e.reject("err.your-password-confirmation-did-not-match-with-password", "Your password confirmation did not match with password."); } }  boolean supports(Class<?> clazz); void validate(Object clazz, Errors e); }
ChangePasswordValidator implements Validator { public void validate(Object clazz, Errors e) { PasswordReset obj = (PasswordReset) clazz; ValidationUtils.rejectIfEmptyOrWhitespace(e, "emailAddress", "error.required", new Object[]{"Email Address"}); if (!StringUtil.isEmpty(obj.getEmailAddress()) && !userDao.isRegisteredByEmail(obj.getEmailAddress())) { e.rejectValue("emailAddress","msg.email-address-is-not-registered", "Sorry, but your email address is not registered."); } ValidationUtils.rejectIfEmptyOrWhitespace(e, "password", "error.required", new Object[]{"Password"}); ValidationUtils.rejectIfEmptyOrWhitespace(e, "confirmPassword", "error.required", new Object[]{"Confirm Password"}); if (!StringUtil.isEmpty(obj.getPassword()) && (obj.getPassword().length()<6)) { e.reject("err.your-password-should-be-at-least-6-characters-long","Your password should be at least 6 characters long."); } if (!StringUtil.isEmpty(obj.getPassword()) && !StringUtil.isEmpty(obj.getConfirmPassword()) && !obj.getPassword().equals(obj.getConfirmPassword()) ) { e.reject("err.your-password-confirmation-did-not-match-with-password", "Your password confirmation did not match with password."); } }  boolean supports(Class<?> clazz); void validate(Object clazz, Errors e);  }