aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test/java/com/vaadin/ui/DateFieldTestCase.java
blob: 43bfefc681cc62832375ead6a917fb7dd9b2c81b (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
package com.vaadin.ui;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsNull.nullValue;

import java.util.Date;

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

public class DateFieldTestCase {

    private DateField dateField;
    private Date date;

    @Before
    public void setup() {
        dateField = new DateField();
        date = new Date();
    }

    @Test
    public void rangeStartIsSetToNull() {
        dateField.setRangeStart(null);

        assertThat(dateField.getRangeStart(), is(nullValue()));
    }

    @Test
    public void rangeStartIsImmutable() {
        long expectedTime = date.getTime();

        dateField.setRangeStart(date);
        date.setTime(expectedTime + 1);

        assertThat(dateField.getRangeStart().getTime(), is(expectedTime));
    }

    @Test
    public void rangeEndIsSetToNull() {
        dateField.setRangeEnd(null);

        assertThat(dateField.getRangeEnd(), is(nullValue()));
    }

    @Test
    public void rangeEndIsImmutable() {
        long expectedTime = date.getTime();

        dateField.setRangeEnd(date);
        date.setTime(expectedTime + 1);

        assertThat(dateField.getRangeEnd().getTime(), is(expectedTime));
    }
}