Browse Source

Make tests pass in any timezone (#19813)

Change-Id: I78411b92a5b3c2f04ed8a15ebd2c183aa1af4ab9
tags/7.7.0.alpha3
Marco Collovati 8 years ago
parent
commit
1e7893d743

+ 2
- 1
server/src/test/java/com/vaadin/tests/design/DesignFormatterTest.java View File

Date result = formatter.parse(formatted, Date.class); Date result = formatter.parse(formatted, Date.class);


// writing will always give full date string // writing will always give full date string
assertEquals("2012-02-17 00:00:00+0200", formatted);
String timeZone = new SimpleDateFormat("Z").format(date);
assertEquals("2012-02-17 00:00:00" + timeZone, formatted);
assertEquals(date, result); assertEquals(date, result);


// try short date as well // try short date as well

+ 13
- 8
server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java View File

*/ */
package com.vaadin.tests.server.component.datefield; package com.vaadin.tests.server.component.datefield;


import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.TimeZone; import java.util.TimeZone;




/** /**
* Tests the declarative support for implementations of {@link DateField}. * Tests the declarative support for implementations of {@link DateField}.
*
* @since 7.4
*
* @author Vaadin Ltd * @author Vaadin Ltd
* @since 7.4
*/ */
public class DateFieldDeclarativeTest extends DeclarativeTestBase<DateField> { public class DateFieldDeclarativeTest extends DeclarativeTestBase<DateField> {


} }


private String getTimezoneDesign() { private String getTimezoneDesign() {
return "<vaadin-date-field range-start=\"2014-05-05 00:00:00+0300\" range-end=\"2014-06-05 00:00:00+0300\" date-out-of-range-message=\"Please select a sensible date\" date-format=\"yyyy-MM-dd\" lenient show-iso-week-numbers parse-error-message=\"You are doing it wrong\" time-zone=\"GMT+05:00\" value=\"2014-05-15 00:00:00+0300\"/>";
String timeZone = new SimpleDateFormat("Z").format(new Date());
return String.format("<vaadin-date-field range-start=\"2014-05-05 00:00:00%1$s\" range-end=\"2014-06-05 00:00:00%1$s\" date-out-of-range-message=\"Please select a sensible date\" date-format=\"yyyy-MM-dd\" lenient show-iso-week-numbers parse-error-message=\"You are doing it wrong\" time-zone=\"GMT+05:00\" value=\"2014-05-15 00:00:00%1$s\"/>" ,timeZone);
} }


private DateField getTimezoneExpected() { private DateField getTimezoneExpected() {
@Test @Test
public void writeYearResolution() { public void writeYearResolution() {
// Writing is always done in full resolution.. // Writing is always done in full resolution..
String timeZone = new SimpleDateFormat("Z").format(new Date(2020 - 1900, 1 - 1, 1));
testWrite( testWrite(
getYearResolutionDesign().replace("2020",
"2020-01-01 00:00:00+0200"),
getYearResolutionExpected());
getYearResolutionDesign().replace("2020",
"2020-01-01 00:00:00" + timeZone),
getYearResolutionExpected());
} }


@Test @Test
public void testReadOnlyValue() { public void testReadOnlyValue() {
String design = "<vaadin-date-field readonly resolution='year' value='2020-01-01 00:00:00+0200'/>";
Date date = new Date(2020 - 1900, 1 - 1, 1);
String timeZone = new SimpleDateFormat("Z").format(date);
String design = "<vaadin-date-field readonly resolution='year' value='2020-01-01 00:00:00" + timeZone + "'/>";
DateField df = new DateField(); DateField df = new DateField();
df.setResolution(Resolution.YEAR); df.setResolution(Resolution.YEAR);
df.setValue(new Date(2020 - 1900, 1 - 1, 1));
df.setValue(date);
df.setReadOnly(true); df.setReadOnly(true);


testRead(design, df); testRead(design, df);

Loading…
Cancel
Save