@Test public void input_mismatch() throws Exception { String label = "My Field"; Field field = mockFieldWithLabel(label); MessageFormatter formatter = mockMessageFormatter(); String message = "{message}"; Pattern constraint = Pattern.compile("\\d{4}"); String value = "abc"; train_format(formatter, message, constraint.toString(), label); replay(); Regexp validator = new Regexp(null); try { validator.validate(field, constraint, formatter, value); unreachable(); } catch (ValidationException ex) { assertEquals(ex.getMessage(), message); } verify(); }
public void validate(Field field, Pattern constraintValue, MessageFormatter formatter, String value) throws ValidationException { Matcher matcher = constraintValue.matcher(value); if (!matcher.matches()) throw new ValidationException(buildMessage(formatter, field, constraintValue)); }
Regexp extends AbstractValidator<Pattern, String> { public void validate(Field field, Pattern constraintValue, MessageFormatter formatter, String value) throws ValidationException { Matcher matcher = constraintValue.matcher(value); if (!matcher.matches()) throw new ValidationException(buildMessage(formatter, field, constraintValue)); } }
Regexp extends AbstractValidator<Pattern, String> { public void validate(Field field, Pattern constraintValue, MessageFormatter formatter, String value) throws ValidationException { Matcher matcher = constraintValue.matcher(value); if (!matcher.matches()) throw new ValidationException(buildMessage(formatter, field, constraintValue)); } Regexp(JavaScriptSupport javaScriptSupport); }
Regexp extends AbstractValidator<Pattern, String> { public void validate(Field field, Pattern constraintValue, MessageFormatter formatter, String value) throws ValidationException { Matcher matcher = constraintValue.matcher(value); if (!matcher.matches()) throw new ValidationException(buildMessage(formatter, field, constraintValue)); } Regexp(JavaScriptSupport javaScriptSupport); void render(Field field, Pattern constraintValue, MessageFormatter formatter, MarkupWriter writer,
                       FormSupport formSupport); void validate(Field field, Pattern constraintValue, MessageFormatter formatter, String value); }
Regexp extends AbstractValidator<Pattern, String> { public void validate(Field field, Pattern constraintValue, MessageFormatter formatter, String value) throws ValidationException { Matcher matcher = constraintValue.matcher(value); if (!matcher.matches()) throw new ValidationException(buildMessage(formatter, field, constraintValue)); } Regexp(JavaScriptSupport javaScriptSupport); void render(Field field, Pattern constraintValue, MessageFormatter formatter, MarkupWriter writer,
                       FormSupport formSupport); void validate(Field field, Pattern constraintValue, MessageFormatter formatter, String value);  }