aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test/java/com/vaadin/tests/data/selection/StaleSingleSelectionTest.java
blob: bdcdb46b186f443e7a88a2b4ed00c9fbc79cc7f2 (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
package com.vaadin.tests.data.selection;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.util.Collection;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;

import com.vaadin.data.provider.StrBean;
import com.vaadin.ui.AbstractSingleSelect;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.RadioButtonGroup;

public class StaleSingleSelectionTest
        extends AbstractStaleSelectionTest<AbstractSingleSelect<StrBean>> {

    @Test
    public void testGridSingleSelectionUpdateOnRefreshItem() {
        StrBean toReplace = data.get(0);
        assertNotStale(toReplace);

        select.setValue(toReplace);

        StrBean replacement = new StrBean("Replacement bean", toReplace.getId(),
                -1);
        dataProvider.refreshItem(replacement);

        assertIsStale(toReplace);
        assertFalse("Selection should not contain stale values",
                dataProvider.isStale(select.getValue()));

        assertEquals("Selected item id did not match original.",
                toReplace.getId(), dataProvider.getId(select.getValue()));
    }

    @Parameters(name = "{0}")
    public static Collection<Object[]> getParams() {
        return Stream
                .of(new NativeSelect<>(), new ComboBox<>(),
                        new RadioButtonGroup<>())
                .map(c -> new Object[] { c.getClass().getSimpleName(), c })
                .collect(Collectors.toList());
    }

}