aboutsummaryrefslogtreecommitdiffstats
path: root/compatibility-server/src/test/java/com/vaadin/v7/data/util/sqlcontainer/RowIdTest.java
blob: 7368bacfdfbe5b031d6c4fba39d58cbc1773dbf7 (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
package com.vaadin.v7.data.util.sqlcontainer;

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 org.junit.Test;

public class RowIdTest {

    @Test
    public void constructor_withArrayOfPrimaryKeyColumns_shouldSucceed() {
        RowId id = new RowId(new Object[] { "id", "name" });
        assertArrayEquals(new Object[] { "id", "name" }, id.getId());
    }

    @Test(expected = IllegalArgumentException.class)
    public void constructor_withNullParameter_shouldFail() {
        new RowId(null);
    }

    @Test
    public void hashCode_samePrimaryKeys_sameResult() {
        RowId id = new RowId(new Object[] { "id", "name" });
        RowId id2 = new RowId(new Object[] { "id", "name" });
        assertEquals(id.hashCode(), id2.hashCode());
    }

    @Test
    public void hashCode_differentPrimaryKeys_differentResult() {
        RowId id = new RowId(new Object[] { "id", "name" });
        RowId id2 = new RowId(new Object[] { "id" });
        assertFalse(id.hashCode() == id2.hashCode());
    }

    @Test
    public void equals_samePrimaryKeys_returnsTrue() {
        RowId id = new RowId(new Object[] { "id", "name" });
        RowId id2 = new RowId(new Object[] { "id", "name" });
        assertEquals(id, id2);
    }

    @Test
    public void equals_differentPrimaryKeys_returnsFalse() {
        RowId id = new RowId(new Object[] { "id", "name" });
        RowId id2 = new RowId(new Object[] { "id" });
        assertFalse(id.equals(id2.hashCode()));
    }

    @Test
    public void equals_differentDataType_returnsFalse() {
        RowId id = new RowId(new Object[] { "id", "name" });
        assertFalse(id.equals("Tudiluu"));
        assertFalse(id.equals(new Integer(1337)));
    }

    @Test
    public void toString_defaultCtor_noException() {
        RowId rowId = new RowId();
        assertTrue("Unexpected to string for empty Row Id",
                rowId.toString().isEmpty());
    }
}