@SuppressWarnings("unchecked") @Test public void validator_with_constraint() throws Exception { Validator validator = mockValidator(); TypeCoercer coercer = mockTypeCoercer(); FieldComponent field = newFieldComponent(); MessageFormatter formatter = mockMessageFormatter(); Object inputValue = new Object(); ComponentResources resources = mockComponentResources(); Messages containerMessages = mockMessages(); Integer five = 5; FormSupport fs = mockFormSupport(); ValidatorMacro macro = mockValidatorMacro(); Messages globalMessages = mockMessages(); Map<String, Validator> map = singletonMap("minLength", validator); train_getConstraintType(validator, Integer.class); train_getFormValidationId(fs, "myform"); train_coerce(coercer, "5", Integer.class, five); train_getComponentResources(field, resources); train_getId(resources, "fred"); train_getContainerMessages(resources, containerMessages); train_alwaysNull(macro); train_contains(containerMessages, "myform-fred-minLength-message", false); train_contains(containerMessages, "fred-minLength-message", false); train_getMessageKey(validator, "key"); train_getMessageFormatter(globalMessages, "key", formatter); train_isRequired(validator, false); train_getValueType(validator, Object.class); validator.validate(field, five, formatter, inputValue); replay(); FieldValidatorSource source = new FieldValidatorSourceImpl(globalMessages, coercer, fs, map, macro); FieldValidator fieldValidator = source.createValidator(field, "minLength", "5"); fieldValidator.validate(inputValue); verify(); }
public FieldValidator createValidator(Field field, String validatorType, String constraintValue) { Component component = (Component) field; assert InternalUtils.isNonBlank(validatorType); ComponentResources componentResources = component.getComponentResources(); String overrideId = componentResources.getId(); Messages overrideMessages = componentResources.getContainerMessages(); return createValidator(field, validatorType, constraintValue, overrideId, overrideMessages, null); }
FieldValidatorSourceImpl implements FieldValidatorSource { public FieldValidator createValidator(Field field, String validatorType, String constraintValue) { Component component = (Component) field; assert InternalUtils.isNonBlank(validatorType); ComponentResources componentResources = component.getComponentResources(); String overrideId = componentResources.getId(); Messages overrideMessages = componentResources.getContainerMessages(); return createValidator(field, validatorType, constraintValue, overrideId, overrideMessages, null); } }
FieldValidatorSourceImpl implements FieldValidatorSource { public FieldValidator createValidator(Field field, String validatorType, String constraintValue) { Component component = (Component) field; assert InternalUtils.isNonBlank(validatorType); ComponentResources componentResources = component.getComponentResources(); String overrideId = componentResources.getId(); Messages overrideMessages = componentResources.getContainerMessages(); return createValidator(field, validatorType, constraintValue, overrideId, overrideMessages, null); } FieldValidatorSourceImpl(Messages globalMessages, TypeCoercer typeCoercer,
                                    FormSupport formSupport, Map<String, Validator> validators, ValidatorMacro validatorMacro); }
FieldValidatorSourceImpl implements FieldValidatorSource { public FieldValidator createValidator(Field field, String validatorType, String constraintValue) { Component component = (Component) field; assert InternalUtils.isNonBlank(validatorType); ComponentResources componentResources = component.getComponentResources(); String overrideId = componentResources.getId(); Messages overrideMessages = componentResources.getContainerMessages(); return createValidator(field, validatorType, constraintValue, overrideId, overrideMessages, null); } FieldValidatorSourceImpl(Messages globalMessages, TypeCoercer typeCoercer,
                                    FormSupport formSupport, Map<String, Validator> validators, ValidatorMacro validatorMacro); FieldValidator createValidator(Field field, String validatorType, String constraintValue); FieldValidator createValidator(Field field, String validatorType, String constraintValue, String overrideId,
                                          Messages overrideMessages, Locale locale); FieldValidator createValidators(Field field, String specification); }
FieldValidatorSourceImpl implements FieldValidatorSource { public FieldValidator createValidator(Field field, String validatorType, String constraintValue) { Component component = (Component) field; assert InternalUtils.isNonBlank(validatorType); ComponentResources componentResources = component.getComponentResources(); String overrideId = componentResources.getId(); Messages overrideMessages = componentResources.getContainerMessages(); return createValidator(field, validatorType, constraintValue, overrideId, overrideMessages, null); } FieldValidatorSourceImpl(Messages globalMessages, TypeCoercer typeCoercer,
                                    FormSupport formSupport, Map<String, Validator> validators, ValidatorMacro validatorMacro); FieldValidator createValidator(Field field, String validatorType, String constraintValue); FieldValidator createValidator(Field field, String validatorType, String constraintValue, String overrideId,
                                          Messages overrideMessages, Locale locale); FieldValidator createValidators(Field field, String specification);  }