RoleNameValidator implements ConstraintValidator<ValidRoleName, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (StringUtils.isBlank(value)) { return true; } return Pattern.matches("^" + DocumentrConstants.ROLE_NAME_PATTERN + "$", value); }  @Override void initialize(ValidRoleName annotation); @Override boolean isValid(String value, ConstraintValidatorContext context);  }
@Test public void isValid() { RoleNameValidator validator = new RoleNameValidator(); assertTrue(validator.isValid(null, null)); assertTrue(validator.isValid(StringUtils.EMPTY, null)); assertTrue(validator.isValid("role", null)); assertTrue(validator.isValid("Role 123", null)); assertFalse(validator.isValid("role.123", null)); }