PasswordValidator { public void validate(final String password) { if (!passwordValidator.test(password)) { throw new ValidationErrorsException(errorMessage); } } @Inject  PasswordValidator(
      @Nullable @Named("nexus.password.validator") final String passwordValidator,
      @Nullable @Named("nexus.password.validator.message") final String errorMessage); void validate(final String password);  }
@Test public void testValidate_noValidation() { PasswordValidator underTest = new PasswordValidator(null, null); underTest.validate("foo"); }
@Test public void testValidate_passValidation() { PasswordValidator underTest = new PasswordValidator(".*", null); underTest.validate("foo"); }
@Test public void testValidate_failValidation() { PasswordValidator underTest = new PasswordValidator("[a]+", null); thrown.expect(ValidationErrorsException.class); thrown.expectMessage("Password does not match corporate policy"); underTest.validate("foo"); }
@Test public void testValidate_failValidationCustomErrorMessage() { PasswordValidator underTest = new PasswordValidator("[a]+", "Bad bad bad"); thrown.expect(ValidationErrorsException.class); thrown.expectMessage("Bad bad bad"); underTest.validate("foo"); }