blob: 5f4b597157389d0ea01618c6714b3de26662f4ff (
plain)
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
|
package com.vaadin.ui;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Before;
import org.junit.Test;
import com.vaadin.data.provider.DataProvider;
import com.vaadin.server.ServerRpcManager;
import com.vaadin.shared.data.selection.SelectionServerRpc;
public class RadioButtonGroupTest {
private RadioButtonGroup<String> radioButtonGroup;
@Before
public void setUp() {
radioButtonGroup = new RadioButtonGroup<>();
// Intentional deviation from upcoming selection order
radioButtonGroup.setDataProvider(
DataProvider.ofItems("Third", "Second", "First"));
}
@Test
public void apiSelectionChange_notUserOriginated() {
AtomicInteger listenerCount = new AtomicInteger(0);
radioButtonGroup.addSelectionListener(event -> {
listenerCount.incrementAndGet();
assertFalse(event.isUserOriginated());
});
radioButtonGroup.setValue("First");
radioButtonGroup.setValue("Second");
radioButtonGroup.setValue(null);
radioButtonGroup.setValue(null);
assertEquals(3, listenerCount.get());
}
@Test
public void rpcSelectionChange_userOriginated() {
AtomicInteger listenerCount = new AtomicInteger(0);
radioButtonGroup.addSelectionListener(event -> {
listenerCount.incrementAndGet();
assertTrue(event.isUserOriginated());
});
SelectionServerRpc rpc = ServerRpcManager.getRpcProxy(radioButtonGroup,
SelectionServerRpc.class);
rpc.select(getItemKey("First"));
rpc.select(getItemKey("Second"));
rpc.deselect(getItemKey("Second"));
assertEquals(3, listenerCount.get());
}
private String getItemKey(String dataObject) {
return radioButtonGroup.getDataCommunicator().getKeyMapper()
.key(dataObject);
}
}
|