]> source.dussan.org Git - vaadin-framework.git/blob
83c45f94dbbf714cf556038936f17c3c4cca6545
[vaadin-framework.git] /
1 package com.vaadin.tests.server.component.textfield;
2
3 import junit.framework.TestCase;
4
5 import com.vaadin.data.util.ObjectProperty;
6 import com.vaadin.data.validator.RangeValidator;
7 import com.vaadin.tests.data.converter.ConverterFactoryTest.ConvertTo42;
8 import com.vaadin.ui.TextField;
9
10 public class TextFieldWithConverterAndValidatorTest extends TestCase {
11
12     private TextField field;
13     private ObjectProperty<Integer> property;
14
15     @Override
16     protected void setUp() throws Exception {
17         super.setUp();
18
19         field = new TextField();
20         field.setInvalidAllowed(false);
21     }
22
23     public void testConvert42AndValidator() {
24         property = new ObjectProperty<Integer>(123);
25         field.setConverter(new ConvertTo42());
26         field.setPropertyDataSource(property);
27
28         field.addValidator(new RangeValidator<Integer>("Incorrect value",
29                 Integer.class, 42, 42));
30
31         // succeeds
32         field.setValue("a");
33         // succeeds
34         field.setValue("42");
35         // succeeds - no validation
36         property.setValue(42);
37
38         // nulls
39
40         // succeeds - validate() converts field value back to property type
41         // before validation
42         property.setValue(null);
43         field.validate();
44         // succeeds
45         field.setValue(null);
46     }
47
48     // TODO test converter changing value to null with validator
49 }