RegexValidation implements Validation<String> { @Override public ValidationResult validate(String value) { boolean error = Optional.ofNullable(value).map(ss -> pattern.matcher(ss).matches()).orElse(true); return new ValidationResult(!error,new LanguageText().en("Input match pattern '" + pattern.pattern() + "'")); } RegexValidation(Pattern pattern); @Override ValidationResult validate(String value);  }
@Test public void test_RegexValidation() { RegexValidation validation = new RegexValidation(Pattern.compile("[0-9]*")); Assertions.assertTrue(validation.validate("sfdsfdsfd").validationFailed()); Assertions.assertFalse(validation.validate("1234").validationFailed()); Assertions.assertFalse(validation.validate(null).validationFailed()); }