]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add DateFieldTest. (#15342)
authorSauli Tähkäpää <sauli@vaadin.com>
Tue, 16 Dec 2014 13:20:01 +0000 (15:20 +0200)
committerVaadin Code Review <review@vaadin.com>
Fri, 19 Dec 2014 09:37:55 +0000 (09:37 +0000)
Change-Id: I6cf033f060d90fba47242028ab4098020fa6b3dc

server/tests/src/com/vaadin/ui/DateFieldTests.java [new file with mode: 0644]

diff --git a/server/tests/src/com/vaadin/ui/DateFieldTests.java b/server/tests/src/com/vaadin/ui/DateFieldTests.java
new file mode 100644 (file)
index 0000000..6a75b46
--- /dev/null
@@ -0,0 +1,56 @@
+package com.vaadin.ui;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Date;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNull.nullValue;
+
+public class DateFieldTests {
+
+    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));
+    }
+}