1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
package com.vaadin.data;
import static org.junit.Assert.assertEquals;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.CheckBoxGroup;
import com.vaadin.ui.ColorPicker;
import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.Slider;
public class BinderComponentTest
extends BinderTestBase<Binder<String>, String> {
enum TestValues {
TRUE, FALSE, FILE_NOT_FOUND
}
@Before
public void setUp() {
binder = new Binder<>();
item = "Foo";
}
@Test
public void slider_bind_null() {
double minValue = 10.5d;
double initialValue = 28.2d;
Slider slider = new Slider();
slider.setResolution(1);
slider.setMin(minValue);
testFieldNullRepresentation(initialValue, slider);
}
@Test
public void colorpicker_bind_null() {
testFieldNullRepresentation(new Color(123, 254, 213),
new ColorPicker());
}
@Test
public void richtextarea_bind_null() {
testFieldNullRepresentation("Test text", new RichTextArea());
}
@Test
public void checkbox_bind_null() {
testFieldNullRepresentation(true, new CheckBox());
}
@Test
public void checkboxgroup_bind_null() {
CheckBoxGroup<TestValues> checkBoxGroup = new CheckBoxGroup<>();
checkBoxGroup.setItems(TestValues.values());
testFieldNullRepresentation(
Collections.singleton(TestValues.FILE_NOT_FOUND),
checkBoxGroup);
}
private <T> void testFieldNullRepresentation(T initialValue,
HasValue<T> field) {
binder.bind(field, t -> null, (str, val) -> {});
field.setValue(initialValue);
assertEquals("Initial value of field unexpected", initialValue,
field.getValue());
binder.setBean(item);
assertEquals("Null representation for field failed",
field.getEmptyValue(), field.getValue());
}
}
|