]> source.dussan.org Git - vaadin-framework.git/blob
89d21728e4c8ef88bbef48c87ba8dbf5e435b413
[vaadin-framework.git] /
1 package com.vaadin.tests.server.component.textfield;
2
3 import junit.framework.TestCase;
4
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;
10
11 public class TextFieldWithConverterAndValidator extends TestCase {
12
13     private TextField field;
14     private ObjectProperty<Integer> property;
15
16     @Override
17     protected void setUp() throws Exception {
18         super.setUp();
19
20         field = new TextField();
21         field.setInvalidAllowed(false);
22     }
23
24     public void testConvert42AndValidator() {
25         property = new ObjectProperty<Integer>(123);
26         field.setConverter(new ConvertTo42());
27         field.setPropertyDataSource(property);
28
29         field.addValidator(new RangeValidator<Integer>("Incorrect value",
30                 Integer.class, 42, 42));
31
32         // succeeds
33         field.setValue("a");
34         // succeeds
35         field.setValue("42");
36         // succeeds - no validation
37         property.setValue(42);
38
39         // nulls
40
41         // fails
42         try {
43             property.setValue(null);
44             fail();
45         } catch (InvalidValueException e) {
46             // should fail
47         }
48         // succeeds
49         field.setValue(null);
50     }
51
52     // TODO test converter changing value to null with validator
53 }