blob: 026388d6238ad6a77b51a2d7fe8a79ab296c4bb1 (
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
|
package com.vaadin.ui;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.time.LocalDate;
import org.junit.Before;
import org.junit.Test;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
public class DateFieldTestCase {
private AbstractLocalDateField dateField;
private LocalDate date;
@Rule
public transient ExpectedException exceptionRule = ExpectedException.none();
@Before
public void setup() {
dateField = new AbstractLocalDateField() {
};
date = LocalDate.now();
}
@Test
public void rangeStartIsSetToNull() {
dateField.setRangeStart(null);
assertThat(dateField.getRangeStart(), is(nullValue()));
}
@Test
public void rangeStartIsAcceptedAsValue() {
dateField.setRangeStart(date);
dateField.setValue(date);
assertNull(dateField.getComponentError());
}
@Test
public void belowRangeStartIsNotAcceptedAsValue() {
LocalDate currentDate = dateField.getValue();
dateField.setRangeStart(date);
exceptionRule.expect(IllegalArgumentException.class);
dateField.setValue(date.minusDays(1));
assertThat(dateField.getValue(), is(currentDate));
}
@Test
public void rangeEndIsSetToNull() {
dateField.setRangeEnd(null);
assertThat(dateField.getRangeEnd(), is(nullValue()));
}
@Test
public void rangeEndIsAcceptedAsValue() {
dateField.setRangeEnd(date);
dateField.setValue(date);
assertNull(dateField.getComponentError());
}
@Test
public void aboveRangeEndIsNotAcceptedAsValue() {
LocalDate currentDate = dateField.getValue();
dateField.setRangeEnd(date);
exceptionRule.expect(IllegalArgumentException.class);
dateField.setValue(date.plusDays(1));
assertThat(dateField.getValue(), is(currentDate));
}
}
|