### Question:
ValidationService implements Reloadable { public ValidationResult validatePassword(String password, String username) { String passLow = password.toLowerCase(); if (!passwordRegex.matcher(passLow).matches()) { return new ValidationResult(MessageKey.PASSWORD_CHARACTERS_ERROR, passwordRegex.pattern()); } else if (passLow.equalsIgnoreCase(username)) { return new ValidationResult(MessageKey.PASSWORD_IS_USERNAME_ERROR); } else if (password.length() < settings.getProperty(SecuritySettings.MIN_PASSWORD_LENGTH) || password.length() > settings.getProperty(SecuritySettings.MAX_PASSWORD_LENGTH)) { return new ValidationResult(MessageKey.INVALID_PASSWORD_LENGTH); } else if (settings.getProperty(SecuritySettings.UNSAFE_PASSWORDS).contains(passLow)) { return new ValidationResult(MessageKey.PASSWORD_UNSAFE_ERROR); } return new ValidationResult(); } ValidationService(); @PostConstruct @Override void reload(); ValidationResult validatePassword(String password, String username); boolean validateEmail(String email); boolean isEmailFreeForRegistration(String email, CommandSender sender); boolean isCountryAdmitted(String hostAddress); boolean isUnrestricted(String name); boolean fulfillsNameRestrictions(Player player);  }### Answer:
@Test public void shouldRejectPasswordSameAsUsername() { ValidationResult error = validationService.validatePassword("bobby", "Bobby"); assertErrorEquals(error, MessageKey.PASSWORD_IS_USERNAME_ERROR); }
@Test public void shouldRejectPasswordNotMatchingPattern() { ValidationResult error = validationService.validatePassword("invalid1234", "myPlayer"); assertErrorEquals(error, MessageKey.PASSWORD_CHARACTERS_ERROR, "[a-zA-Z]+"); }
@Test public void shouldRejectTooShortPassword() { ValidationResult error = validationService.validatePassword("ab", "tester"); assertErrorEquals(error, MessageKey.INVALID_PASSWORD_LENGTH); }
@Test public void shouldRejectTooLongPassword() { ValidationResult error = validationService.validatePassword(Strings.repeat("a", 30), "player"); assertErrorEquals(error, MessageKey.INVALID_PASSWORD_LENGTH); }
@Test public void shouldRejectUnsafePassword() { ValidationResult error = validationService.validatePassword("unsafe", "playertest"); assertErrorEquals(error, MessageKey.PASSWORD_UNSAFE_ERROR); }
@Test public void shouldAcceptValidPassword() { ValidationResult error = validationService.validatePassword("safePass", "some_user"); assertThat(error.hasError(), equalTo(false)); }