@Test public void success() { FieldValidatorSource source = mockFieldValidatorSource(); ComponentResources container = mockComponentResources(); ComponentResources component = mockComponentResources(); FieldComponent instance = mockFieldComponent(); Location l = mockLocation(); FieldValidator validator = mockFieldValidator(); String expression = "required,minLength=5"; train_getComponent(component, instance); expect(source.createValidators(instance, expression)).andReturn(validator); replay(); BindingFactory factory = new ValidateBindingFactory(source, interner); Binding binding = factory.newBinding("descrip", container, component, expression, l); assertSame(binding.get(), validator); verify(); }
public Binding newBinding(String description, ComponentResources container, ComponentResources component, final String expression, Location location) { Object fieldAsObject = component.getComponent(); if (!Field.class.isInstance(fieldAsObject)) throw new TapestryException(String.format("Component '%s' is not a field (it does not implement the Field interface) and may not be used with the validate: binding prefix.", component.getCompleteId()), location, null); final Field field = (Field) fieldAsObject; return new InvariantBinding(location, FieldValidator.class, interner.intern(description + ": " + expression)) { public Object get() { return fieldValidatorSource.createValidators(field, expression); } }; }
ValidateBindingFactory implements BindingFactory { public Binding newBinding(String description, ComponentResources container, ComponentResources component, final String expression, Location location) { Object fieldAsObject = component.getComponent(); if (!Field.class.isInstance(fieldAsObject)) throw new TapestryException(String.format("Component '%s' is not a field (it does not implement the Field interface) and may not be used with the validate: binding prefix.", component.getCompleteId()), location, null); final Field field = (Field) fieldAsObject; return new InvariantBinding(location, FieldValidator.class, interner.intern(description + ": " + expression)) { public Object get() { return fieldValidatorSource.createValidators(field, expression); } }; } }
ValidateBindingFactory implements BindingFactory { public Binding newBinding(String description, ComponentResources container, ComponentResources component, final String expression, Location location) { Object fieldAsObject = component.getComponent(); if (!Field.class.isInstance(fieldAsObject)) throw new TapestryException(String.format("Component '%s' is not a field (it does not implement the Field interface) and may not be used with the validate: binding prefix.", component.getCompleteId()), location, null); final Field field = (Field) fieldAsObject; return new InvariantBinding(location, FieldValidator.class, interner.intern(description + ": " + expression)) { public Object get() { return fieldValidatorSource.createValidators(field, expression); } }; } ValidateBindingFactory(FieldValidatorSource fieldValidatorSource, StringInterner interner); }
ValidateBindingFactory implements BindingFactory { public Binding newBinding(String description, ComponentResources container, ComponentResources component, final String expression, Location location) { Object fieldAsObject = component.getComponent(); if (!Field.class.isInstance(fieldAsObject)) throw new TapestryException(String.format("Component '%s' is not a field (it does not implement the Field interface) and may not be used with the validate: binding prefix.", component.getCompleteId()), location, null); final Field field = (Field) fieldAsObject; return new InvariantBinding(location, FieldValidator.class, interner.intern(description + ": " + expression)) { public Object get() { return fieldValidatorSource.createValidators(field, expression); } }; } ValidateBindingFactory(FieldValidatorSource fieldValidatorSource, StringInterner interner); Binding newBinding(String description, ComponentResources container,
                              ComponentResources component, final String expression, Location location); }
ValidateBindingFactory implements BindingFactory { public Binding newBinding(String description, ComponentResources container, ComponentResources component, final String expression, Location location) { Object fieldAsObject = component.getComponent(); if (!Field.class.isInstance(fieldAsObject)) throw new TapestryException(String.format("Component '%s' is not a field (it does not implement the Field interface) and may not be used with the validate: binding prefix.", component.getCompleteId()), location, null); final Field field = (Field) fieldAsObject; return new InvariantBinding(location, FieldValidator.class, interner.intern(description + ": " + expression)) { public Object get() { return fieldValidatorSource.createValidators(field, expression); } }; } ValidateBindingFactory(FieldValidatorSource fieldValidatorSource, StringInterner interner); Binding newBinding(String description, ComponentResources container,
                              ComponentResources component, final String expression, Location location);  }