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
79
80
81
82
83
84
|
package com.vaadin.data;
import static org.junit.Assert.assertEquals;
import java.util.Locale;
import java.util.Objects;
import org.junit.Before;
import org.junit.Test;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
public class ValueContextTest extends UI {
private static final Locale UI_LOCALE = Locale.GERMAN;
private static final Locale COMPONENT_LOCALE = Locale.FRENCH;
private TextField textField;
@Test
public void locale_from_component() {
textField.setLocale(COMPONENT_LOCALE);
ValueContext fromComponent = new ValueContext(textField);
Locale locale = fromComponent.getLocale().orElse(null);
Objects.requireNonNull(locale);
assertEquals("Unexpected locale from component", COMPONENT_LOCALE,
locale);
}
@Test
public void locale_from_ui() {
ValueContext fromComponent = new ValueContext(textField);
Locale locale = fromComponent.getLocale().orElse(null);
Objects.requireNonNull(locale);
assertEquals("Unexpected locale from component", UI_LOCALE, locale);
}
@Test
public void default_locale() {
setLocale(null);
ValueContext fromComponent = new ValueContext(textField);
Locale locale = fromComponent.getLocale().orElse(null);
Objects.requireNonNull(locale);
assertEquals("Unexpected locale from component", Locale.getDefault(),
locale);
}
@Test
public void testHasValue1() {
setLocale(null);
ValueContext fromComponent = new ValueContext(textField);
assertEquals(textField, fromComponent.getHasValue().get());
}
@Test
public void testHasValue2() {
setLocale(null);
ValueContext fromComponent = new ValueContext(new CheckBox(),
textField);
assertEquals(textField, fromComponent.getHasValue().get());
}
@Test
public void testHasValue3() {
setLocale(null);
ValueContext fromComponent = new ValueContext(new CheckBox(), textField,
Locale.CANADA);
assertEquals(textField, fromComponent.getHasValue().get());
assertEquals(Locale.CANADA, fromComponent.getLocale().get());
}
@Before
public void setUp() {
setLocale(UI_LOCALE);
textField = new TextField();
setContent(textField);
}
@Override
public void init(VaadinRequest request) {
}
}
|