aboutsummaryrefslogtreecommitdiffstats
path: root/compatibility-server/src/test/java/com/vaadin/v7/ui/TableTest.java
blob: 72ccd1d108bee83cbcc9d8737525a0dfd8ff9c93 (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
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.Collection;

import org.junit.Before;
import org.junit.Test;

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

public class TableTest {

    Table table;

    @Before
    public void init() {
        table = new Table();
    }

    @Test
    public void initiallyEmpty() {
        assertTrue(table.isEmpty());
    }

    @Test
    public void emptyAfterClearSingleSelect() {
        table.setContainerDataSource(
                BeanItemContainerGenerator.createContainer(100));
        assertTrue(table.isEmpty());
        Object first = table.getContainerDataSource().getItemIds().iterator()
                .next();
        table.setValue(first);
        assertEquals(first, table.getValue());
        assertFalse(table.isEmpty());
        table.clear();
        assertEquals(null, table.getValue());
        assertTrue(table.isEmpty());
    }

    @Test
    public void emptyAfterClearMultiSelect() {
        table.setMultiSelect(true);
        table.setContainerDataSource(
                BeanItemContainerGenerator.createContainer(100));

        assertTrue(table.isEmpty());
        assertArrayEquals(new Object[] {},
                ((Collection) table.getValue()).toArray());

        Object first = table.getContainerDataSource().getItemIds().iterator()
                .next();
        table.select(first);
        assertArrayEquals(new Object[] { first },
                ((Collection) table.getValue()).toArray());
        assertFalse(table.isEmpty());

        table.clear();
        assertArrayEquals(new Object[] {},
                ((Collection) table.getValue()).toArray());
        assertTrue(table.isEmpty());
    }

}