MacroNameValidator implements ConstraintValidator<ValidMacroName, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (StringUtils.isBlank(value)) { return true; } return Pattern.matches("^" + DocumentrConstants.MACRO_NAME_PATTERN + "$", value); }  @Override void initialize(ValidMacroName annotation); @Override boolean isValid(String value, ConstraintValidatorContext context);  }
@Test public void isValid() { MacroNameValidator validator = new MacroNameValidator(); assertTrue(validator.isValid(null, null)); assertTrue(validator.isValid(StringUtils.EMPTY, null)); assertTrue(validator.isValid("macro", null)); assertTrue(validator.isValid("myMacro_123", null)); assertFalse(validator.isValid("macro.xyz", null)); assertFalse(validator.isValid("macro/xyz", null)); }