1 package com.vaadin.tests.server.component.textfield;
3 import junit.framework.TestCase;
5 import com.vaadin.data.Validator.InvalidValueException;
6 import com.vaadin.data.util.ObjectProperty;
7 import com.vaadin.data.validator.RangeValidator;
8 import com.vaadin.tests.data.converter.ConverterFactory.ConvertTo42;
9 import com.vaadin.ui.TextField;
11 public class TextFieldWithConverterAndValidator extends TestCase {
13 private TextField field;
14 private ObjectProperty<Integer> property;
17 protected void setUp() throws Exception {
20 field = new TextField();
21 field.setInvalidAllowed(false);
24 public void testConvert42AndValidator() {
25 property = new ObjectProperty<Integer>(123);
26 field.setConverter(new ConvertTo42());
27 field.setPropertyDataSource(property);
29 field.addValidator(new RangeValidator<Integer>("Incorrect value",
30 Integer.class, 42, 42));
36 // succeeds - no validation
37 property.setValue(42);
43 property.setValue(null);
45 } catch (InvalidValueException e) {
52 // TODO test converter changing value to null with validator