@SuppressWarnings("unchecked") @Test public void single_validator_via_specification() throws Exception { Validator validator = mockValidator(); TypeCoercer coercer = mockTypeCoercer(); FieldComponent field = newFieldComponent(); Messages messages = mockMessages(); MessageFormatter formatter = mockMessageFormatter(); Object inputValue = new Object(); ComponentResources resources = mockComponentResources(); Messages containerMessages = mockMessages(); FormSupport fs = mockFormSupport(); Messages globalMessages = mockMessages(); Map<String, Validator> map = singletonMap("required", validator); train_getFormValidationId(fs, "myform"); train_getConstraintType(validator, null); train_getComponentResources(field, resources); train_getId(resources, "fred"); train_getContainerMessages(resources, containerMessages); train_contains(containerMessages, "myform-fred-required-message", false); train_contains(containerMessages, "fred-required-message", false); train_getMessageKey(validator, "key"); train_getMessageFormatter(globalMessages, "key", formatter); train_isRequired(validator, false); train_getValueType(validator, Object.class); validator.validate(field, null, formatter, inputValue); ValidatorMacro macro = mockValidatorMacro(); train_alwaysNull(macro); replay(); FieldValidatorSource source = new FieldValidatorSourceImpl(globalMessages, coercer, fs, map, macro); FieldValidator fieldValidator = source.createValidators(field, "required"); fieldValidator.validate(inputValue); verify(); }
public FieldValidator createValidators(Field field, String specification) { List<ValidatorSpecification> specs = toValidatorSpecifications(specification); List<FieldValidator> fieldValidators = CollectionFactory.newList(); for (ValidatorSpecification spec : specs) { fieldValidators.add(createValidator(field, spec.getValidatorType(), spec.getConstraintValue())); } if (fieldValidators.size() == 1) return fieldValidators.get(0); return new CompositeFieldValidator(fieldValidators); }
FieldValidatorSourceImpl implements FieldValidatorSource { public FieldValidator createValidators(Field field, String specification) { List<ValidatorSpecification> specs = toValidatorSpecifications(specification); List<FieldValidator> fieldValidators = CollectionFactory.newList(); for (ValidatorSpecification spec : specs) { fieldValidators.add(createValidator(field, spec.getValidatorType(), spec.getConstraintValue())); } if (fieldValidators.size() == 1) return fieldValidators.get(0); return new CompositeFieldValidator(fieldValidators); } }
FieldValidatorSourceImpl implements FieldValidatorSource { public FieldValidator createValidators(Field field, String specification) { List<ValidatorSpecification> specs = toValidatorSpecifications(specification); List<FieldValidator> fieldValidators = CollectionFactory.newList(); for (ValidatorSpecification spec : specs) { fieldValidators.add(createValidator(field, spec.getValidatorType(), spec.getConstraintValue())); } if (fieldValidators.size() == 1) return fieldValidators.get(0); return new CompositeFieldValidator(fieldValidators); } FieldValidatorSourceImpl(Messages globalMessages, TypeCoercer typeCoercer,
                                    FormSupport formSupport, Map<String, Validator> validators, ValidatorMacro validatorMacro); }
FieldValidatorSourceImpl implements FieldValidatorSource { public FieldValidator createValidators(Field field, String specification) { List<ValidatorSpecification> specs = toValidatorSpecifications(specification); List<FieldValidator> fieldValidators = CollectionFactory.newList(); for (ValidatorSpecification spec : specs) { fieldValidators.add(createValidator(field, spec.getValidatorType(), spec.getConstraintValue())); } if (fieldValidators.size() == 1) return fieldValidators.get(0); return new CompositeFieldValidator(fieldValidators); } 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 createValidators(Field field, String specification) { List<ValidatorSpecification> specs = toValidatorSpecifications(specification); List<FieldValidator> fieldValidators = CollectionFactory.newList(); for (ValidatorSpecification spec : specs) { fieldValidators.add(createValidator(field, spec.getValidatorType(), spec.getConstraintValue())); } if (fieldValidators.size() == 1) return fieldValidators.get(0); return new CompositeFieldValidator(fieldValidators); } 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);  }