date parsing tests fail when system default TZ is or farther west fix
package org.jooby.internal;
-import static org.easymock.EasyMock.createMock;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import com.google.inject.Injector;
+import com.google.inject.TypeLiteral;
+import com.google.inject.util.Types;
+import com.typesafe.config.ConfigFactory;
+import org.jooby.MediaType;
+import org.jooby.internal.parser.*;
+import org.junit.Test;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
+import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Optional;
-import java.util.SortedSet;
-import java.util.UUID;
+import java.util.*;
-import org.jooby.MediaType;
-import org.jooby.internal.parser.DateParser;
-import org.jooby.internal.parser.LocalDateParser;
-import org.jooby.internal.parser.LocaleParser;
-import org.jooby.internal.parser.ParserExecutor;
-import org.jooby.internal.parser.StaticMethodParser;
-import org.jooby.internal.parser.StringConstructorParser;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import com.google.inject.Injector;
-import com.google.inject.TypeLiteral;
-import com.google.inject.util.Types;
-import com.typesafe.config.ConfigFactory;
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
public class ParamConverterTest {
@@ -135,7 +121,9 @@ public class ParamConverterTest {
ParserExecutor resolver = newParser();
Date date = resolver.convert(TypeLiteral.get(Date.class), data("1393038000000"));
assertNotNull(date);
- assertEquals("22/02/2014", new SimpleDateFormat("dd/MM/yyyy").format(date));
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
+ simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ assertEquals("22/02/2014", simpleDateFormat.format(date));
}
@Test
@@ -399,7 +387,8 @@ public class ParamConverterTest {
BuiltinParser.Optional,
BuiltinParser.Enum,
new DateParser("dd/MM/yyyy"),
- new LocalDateParser(DateTimeFormatter.ofPattern("dd/MM/yyyy")),
+ new LocalDateParser(
+ DateTimeFormatter.ofPattern("dd/MM/yyyy").withZone(ZoneId.of("UTC"))),
new LocaleParser(),
new StaticMethodParser("valueOf"),
new StringConstructorParser(),
