MotechPasswordValidator implements PasswordValidator { @Override public void validate(String password) { CharacterCount count = new CharacterCount(password); if (count.getLowerCase() < minLowerCase || count.getUpperCase() < minUpperCase || count.getDigit() < minDigit || count.getSpecial() < minSpecialChar) { throw new PasswordValidatorException("Invalid password, validator name - " + name); } } MotechPasswordValidator(int minLowerCase, int minUpperCase, int minDigit, int minSpecialChar,
                                   String name, MessageSource messageSource); @Override void validate(String password); @Override String getValidationError(Locale locale); @Override String getName();  }
@Test public void shouldValidatePasswords() { validator.validate("Aaft1$@"); validator.validate("T44sss_$"); validator.validate("Something 123&"); }
@Test(expected = PasswordValidatorException.class) public void shouldFailIfNotEnoughLowerCase() { validator.validate("A2tw*@"); }
@Test(expected = PasswordValidatorException.class) public void shouldFailIfNotEnoughUpperCase() { validator.validate("abw2*@"); }
@Test(expected = PasswordValidatorException.class) public void shouldFailIfNotEnoughDigits() { validator.validate("zzzaV*@"); }
@Test(expected = PasswordValidatorException.class) public void shouldFailIfNotEnoughSpecialChars() { validator.validate("sdfaV234%"); }