@Test public void not_a_field() { FieldValidatorSource source = mockFieldValidatorSource(); ComponentResources container = mockComponentResources(); ComponentResources component = mockComponentResources(); Component instance = mockComponent(); Location l = mockLocation(); train_getComponent(component, instance); train_getCompleteId(component, "foo.Bar:baz"); replay(); BindingFactory factory = new ValidateBindingFactory(source, interner); try { factory.newBinding("descrip", container, component, "zip,zoom", l); } catch (TapestryException ex) { assertEquals( ex.getMessage(), "Component 'foo.Bar:baz' is not a field (it does not implement the Field interface) and may not be used with the validate: binding prefix."); assertSame(ex.getLocation(), l); } 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);  }