MatchesValidationMatcher implements ValidationMatcher { public void validate(String fieldName, String value, List<String> controlParameters, TestContext context) throws ValidationException { String control = controlParameters.get(0); boolean success; try { success = value.matches(control); } catch (PatternSyntaxException e) { throw new ValidationException(this.getClass().getSimpleName() + " failed for field '" + fieldName + "'. Found invalid pattern syntax", e); } if (!success) { throw new ValidationException(this.getClass().getSimpleName() + " failed for field '" + fieldName + "'. Received value is '" + value + "', control value is '" + control + "'"); } }  void validate(String fieldName, String value, List<String> controlParameters, TestContext context);  }
@Test public void testValidateSuccess() { matcher.validate("field", "This is a test", Arrays.asList(".*"), context); matcher.validate("field", "This is a test", Arrays.asList("Thi.*"), context); matcher.validate("field", "This is a test", Arrays.asList(".*test"), context); matcher.validate("field", "aaaab", Arrays.asList("a*b"), context); }