aboutsummaryrefslogtreecommitdiffstats
path: root/compatibility-server/src/test/java/com/vaadin/v7/ui/AbsSelectTest.java
blob: 2c83bea6f94b5f99dcff2e05c68b7e225c0a7156 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.vaadin.v7.ui;

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

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import org.junit.Test;

import com.vaadin.v7.data.util.ObjectProperty;

public class AbsSelectTest {

    @Test
    public void addItemsStrings() {
        NativeSelect ns = new NativeSelect();
        ns.addItems("Foo", "bar", "baz");
        assertEquals(3, ns.size());
        assertArrayEquals(new Object[] { "Foo", "bar", "baz" },
                ns.getItemIds().toArray());
    }

    @Test
    public void addItemsObjects() {
        Object o1 = new Object();
        Object o2 = new Object();
        Object o3 = new Object();

        NativeSelect ns = new NativeSelect();
        ns.addItems(o1, o2, o3);
        assertEquals(3, ns.size());
        assertArrayEquals(new Object[] { o1, o2, o3 },
                ns.getItemIds().toArray());
    }

    @Test
    public void addItemsStringList() {
        List<String> itemIds = new ArrayList<String>();
        itemIds.add("foo");
        itemIds.add("bar");
        itemIds.add("baz");
        NativeSelect ns = new NativeSelect();
        ns.addItems(itemIds);
        assertEquals(3, ns.size());
        assertArrayEquals(new Object[] { "foo", "bar", "baz" },
                ns.getItemIds().toArray());
    }

    @Test
    public void addItemsObjectList() {
        Object o1 = new Object();
        Object o2 = new Object();
        Object o3 = new Object();
        List<Object> itemIds = new ArrayList<Object>();
        itemIds.add(o1);
        itemIds.add(o2);
        itemIds.add(o3);
        NativeSelect ns = new NativeSelect();
        ns.addItems(itemIds);
        assertEquals(3, ns.size());
        assertArrayEquals(new Object[] { o1, o2, o3 },
                ns.getItemIds().toArray());

    }

    @Test
    public void singleSelectInitiallyEmpty() {
        AbstractSelect s = new ListSelect();
        assertTrue(s.isEmpty());
    }

    @Test
    public void singleSelectEmptyAfterClearUsingPDS() {
        AbstractSelect s = new ListSelect();
        s.addItem("foo");
        s.addItem("bar");
        s.setPropertyDataSource(new ObjectProperty<String>("foo"));

        assertFalse(s.isEmpty());
        s.clear();
        assertTrue(s.isEmpty());
    }

    @Test
    public void singleSelectEmptyAfterClear() {
        AbstractSelect s = new ListSelect();
        s.addItem("foo");
        s.addItem("bar");
        s.setValue("bar");

        assertFalse(s.isEmpty());
        s.clear();
        assertTrue(s.isEmpty());
    }

    @Test
    public void multiSelectInitiallyEmpty() {
        AbstractSelect s = new ListSelect();
        s.setMultiSelect(true);
        assertTrue(s.isEmpty());
    }

    @Test
    public void multiSelectEmptyAfterClearUsingPDS() {
        AbstractSelect s = new ListSelect();
        s.setMultiSelect(true);
        s.addItem("foo");
        s.addItem("bar");
        HashSet<String> sel = new HashSet<String>();
        sel.add("foo");
        sel.add("bar");
        s.setPropertyDataSource(new ObjectProperty<HashSet>(sel));

        assertFalse(s.isEmpty());
        s.clear();
        assertTrue(s.isEmpty());
    }

    @Test
    public void multiSelectEmptyAfterClear() {
        AbstractSelect s = new ListSelect();
        s.setMultiSelect(true);
        s.addItem("foo");
        s.addItem("bar");
        s.select("foo");
        s.select("bar");

        assertFalse(s.isEmpty());
        s.clear();
        assertTrue(s.isEmpty());
    }

}