summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorAleksi Hietanen <aleksi@vaadin.com>2017-03-30 10:31:51 +0300
committerHenri Sara <henri.sara@gmail.com>2017-03-30 10:31:51 +0300
commitb869d751811f36b3c74ea5c3e44a3e587e0d5b82 (patch)
tree78ad6ae4235789a18c34ccd94a97bc939531b3dd /uitest
parentf9a9f2c4be0e38d936acab88cba45799fa83ff4a (diff)
downloadvaadin-framework-b869d751811f36b3c74ea5c3e44a3e587e0d5b82.tar.gz
vaadin-framework-b869d751811f36b3c74ea5c3e44a3e587e0d5b82.zip
Implement LocalDateRenderer and LocalDateTimeRenderer (#8955)
Closes #8377
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/LocalDateRenderers.java59
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/LocalDateRenderersTest.java38
2 files changed, 97 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/LocalDateRenderers.java b/uitest/src/main/java/com/vaadin/tests/components/grid/LocalDateRenderers.java
new file mode 100644
index 0000000000..e31154eb84
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/LocalDateRenderers.java
@@ -0,0 +1,59 @@
+package com.vaadin.tests.components.grid;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.format.FormatStyle;
+import java.util.Locale;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.renderers.LocalDateRenderer;
+import com.vaadin.ui.renderers.LocalDateTimeRenderer;
+
+public class LocalDateRenderers extends AbstractTestUI {
+
+ private static class TimeBean {
+ private LocalDate localDate;
+ private LocalDateTime localDateTime;
+
+ public TimeBean() {
+ localDate = LocalDate.ofEpochDay(0);
+ localDateTime = localDate.atTime(0, 0);
+ }
+
+ public LocalDate getLocalDate() {
+ return localDate;
+ }
+
+ public LocalDateTime getLocalDateTime() {
+ return localDateTime;
+ }
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ DateTimeFormatter finnishDateFormatter = DateTimeFormatter
+ .ofLocalizedDate(FormatStyle.LONG).withLocale(new Locale("fi"));
+ DateTimeFormatter finnishDateTimeFormatter = DateTimeFormatter
+ .ofLocalizedDateTime(FormatStyle.LONG)
+ .withLocale(new Locale("fi"));
+
+ Grid<TimeBean> grid = new Grid<>();
+ grid.setLocale(new Locale("en"));
+ grid.addColumn(TimeBean::getLocalDate, new LocalDateRenderer())
+ .setCaption("LocalDate");
+ grid.addColumn(TimeBean::getLocalDate,
+ new LocalDateRenderer(finnishDateFormatter, ""))
+ .setCaption("LocalDate, Finnish formatter");
+ grid.addColumn(TimeBean::getLocalDateTime, new LocalDateTimeRenderer())
+ .setCaption("LocalDateTime");
+ grid.addColumn(TimeBean::getLocalDateTime,
+ new LocalDateTimeRenderer(finnishDateTimeFormatter, ""))
+ .setCaption("LocalDateTime, Finnish formatter");
+ grid.setItems(new TimeBean());
+ addComponent(grid);
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/LocalDateRenderersTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/LocalDateRenderersTest.java
new file mode 100644
index 0000000000..76f17edb63
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/LocalDateRenderersTest.java
@@ -0,0 +1,38 @@
+package com.vaadin.tests.components.grid;
+
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.time.format.FormatStyle;
+import java.util.Locale;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class LocalDateRenderersTest extends SingleBrowserTest {
+
+ @Test
+ public void localDate_and_LocalDateTime_rendered_correctly() {
+ openTestURL();
+
+ GridElement grid = $(GridElement.class).first();
+
+ LocalDate epochDate = LocalDate.ofEpochDay(0);
+ Assert.assertEquals(
+ epochDate.format(
+ DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG)
+ .withLocale(new Locale("en"))),
+ grid.getCell(0, 0).getText());
+ Assert.assertEquals("1. tammikuuta 1970", grid.getCell(0, 1).getText());
+ Assert.assertEquals(
+ epochDate.atTime(0, 0)
+ .format(DateTimeFormatter.ofLocalizedDateTime(
+ FormatStyle.LONG, FormatStyle.SHORT)
+ .withLocale(new Locale("en"))),
+ grid.getCell(0, 2).getText());
+ Assert.assertEquals("1. tammikuuta 1970 klo 0.00.00",
+ grid.getCell(0, 3).getText());
+ }
+}