1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
32
32
import java .util .GregorianCalendar ;
33
33
import java .util .List ;
34
34
import java .util .Locale ;
35
+ import java .util .TimeZone ;
35
36
36
37
import org .junit .After ;
37
38
import org .junit .Before ;
@@ -60,12 +61,12 @@ public class DateTimeFormattingTests {
60
61
61
62
62
63
@ Before
63
- public void setUp () {
64
+ public void setup () {
64
65
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar ();
65
- setUp (registrar );
66
+ setup (registrar );
66
67
}
67
68
68
- private void setUp (DateTimeFormatterRegistrar registrar ) {
69
+ private void setup (DateTimeFormatterRegistrar registrar ) {
69
70
conversionService = new FormattingConversionService ();
70
71
DefaultConversionService .addDefaultConverters (conversionService );
71
72
registrar .registerFormatters (conversionService );
@@ -82,7 +83,7 @@ private void setUp(DateTimeFormatterRegistrar registrar) {
82
83
}
83
84
84
85
@ After
85
- public void tearDown () {
86
+ public void cleanup () {
86
87
LocaleContextHolder .setLocale (null );
87
88
DateTimeContextHolder .setDateTimeContext (null );
88
89
}
@@ -98,10 +99,10 @@ public void testBindLocalDate() {
98
99
}
99
100
100
101
@ Test
101
- public void testBindLocalDateWithSpecificStyle () throws Exception {
102
+ public void testBindLocalDateWithSpecificStyle () {
102
103
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar ();
103
104
registrar .setDateStyle (FormatStyle .LONG );
104
- setUp (registrar );
105
+ setup (registrar );
105
106
MutablePropertyValues propertyValues = new MutablePropertyValues ();
106
107
propertyValues .add ("localDate" , "October 31, 2009" );
107
108
binder .bind (propertyValues );
@@ -110,10 +111,10 @@ public void testBindLocalDateWithSpecificStyle() throws Exception {
110
111
}
111
112
112
113
@ Test
113
- public void testBindLocalDateWithSpecificFormatter () throws Exception {
114
+ public void testBindLocalDateWithSpecificFormatter () {
114
115
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar ();
115
116
registrar .setDateFormatter (DateTimeFormatter .ofPattern ("yyyyMMdd" ));
116
- setUp (registrar );
117
+ setup (registrar );
117
118
MutablePropertyValues propertyValues = new MutablePropertyValues ();
118
119
propertyValues .add ("localDate" , "20091031" );
119
120
binder .bind (propertyValues );
@@ -177,7 +178,7 @@ public void testBindLocalDateAnnotatedWithDirectFieldAccessAndError() {
177
178
}
178
179
179
180
@ Test
180
- public void testBindLocalDateFromJavaUtilCalendar () throws Exception {
181
+ public void testBindLocalDateFromJavaUtilCalendar () {
181
182
MutablePropertyValues propertyValues = new MutablePropertyValues ();
182
183
propertyValues .add ("localDate" , new GregorianCalendar (2009 , 9 , 31 , 0 , 0 ));
183
184
binder .bind (propertyValues );
@@ -195,10 +196,10 @@ public void testBindLocalTime() {
195
196
}
196
197
197
198
@ Test
198
- public void testBindLocalTimeWithSpecificStyle () throws Exception {
199
+ public void testBindLocalTimeWithSpecificStyle () {
199
200
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar ();
200
201
registrar .setTimeStyle (FormatStyle .MEDIUM );
201
- setUp (registrar );
202
+ setup (registrar );
202
203
MutablePropertyValues propertyValues = new MutablePropertyValues ();
203
204
propertyValues .add ("localTime" , "12:00:00 PM" );
204
205
binder .bind (propertyValues );
@@ -207,10 +208,10 @@ public void testBindLocalTimeWithSpecificStyle() throws Exception {
207
208
}
208
209
209
210
@ Test
210
- public void testBindLocalTimeWithSpecificFormatter () throws Exception {
211
+ public void testBindLocalTimeWithSpecificFormatter () {
211
212
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar ();
212
213
registrar .setTimeFormatter (DateTimeFormatter .ofPattern ("HHmmss" ));
213
- setUp (registrar );
214
+ setup (registrar );
214
215
MutablePropertyValues propertyValues = new MutablePropertyValues ();
215
216
propertyValues .add ("localTime" , "130000" );
216
217
binder .bind (propertyValues );
@@ -228,7 +229,7 @@ public void testBindLocalTimeAnnotated() {
228
229
}
229
230
230
231
@ Test
231
- public void testBindLocalTimeFromJavaUtilCalendar () throws Exception {
232
+ public void testBindLocalTimeFromJavaUtilCalendar () {
232
233
MutablePropertyValues propertyValues = new MutablePropertyValues ();
233
234
propertyValues .add ("localTime" , new GregorianCalendar (1970 , 0 , 0 , 12 , 0 ));
234
235
binder .bind (propertyValues );
@@ -259,7 +260,7 @@ public void testBindLocalDateTimeAnnotated() {
259
260
}
260
261
261
262
@ Test
262
- public void testBindLocalDateTimeFromJavaUtilCalendar () throws Exception {
263
+ public void testBindLocalDateTimeFromJavaUtilCalendar () {
263
264
MutablePropertyValues propertyValues = new MutablePropertyValues ();
264
265
propertyValues .add ("localDateTime" , new GregorianCalendar (2009 , 9 , 31 , 12 , 0 ));
265
266
binder .bind (propertyValues );
@@ -270,10 +271,10 @@ public void testBindLocalDateTimeFromJavaUtilCalendar() throws Exception {
270
271
}
271
272
272
273
@ Test
273
- public void testBindDateTimeWithSpecificStyle () throws Exception {
274
+ public void testBindDateTimeWithSpecificStyle () {
274
275
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar ();
275
276
registrar .setDateTimeStyle (FormatStyle .MEDIUM );
276
- setUp (registrar );
277
+ setup (registrar );
277
278
MutablePropertyValues propertyValues = new MutablePropertyValues ();
278
279
propertyValues .add ("localDateTime" , LocalDateTime .of (2009 , 10 , 31 , 12 , 0 ));
279
280
binder .bind (propertyValues );
@@ -356,12 +357,19 @@ public void testBindInstant() {
356
357
357
358
@ Test
358
359
@ SuppressWarnings ("deprecation" )
359
- public void testBindInstantFromJavaUtilDate () throws Exception {
360
- MutablePropertyValues propertyValues = new MutablePropertyValues ();
361
- propertyValues .add ("instant" , new Date (109 , 9 , 31 , 12 , 0 ));
362
- binder .bind (propertyValues );
363
- assertEquals (0 , binder .getBindingResult ().getErrorCount ());
364
- assertTrue (binder .getBindingResult ().getFieldValue ("instant" ).toString ().startsWith ("2009-10-31" ));
360
+ public void testBindInstantFromJavaUtilDate () {
361
+ TimeZone defaultZone = TimeZone .getDefault ();
362
+ TimeZone .setDefault (TimeZone .getTimeZone ("GMT" ));
363
+ try {
364
+ MutablePropertyValues propertyValues = new MutablePropertyValues ();
365
+ propertyValues .add ("instant" , new Date (109 , 9 , 31 , 12 , 0 ));
366
+ binder .bind (propertyValues );
367
+ assertEquals (0 , binder .getBindingResult ().getErrorCount ());
368
+ assertTrue (binder .getBindingResult ().getFieldValue ("instant" ).toString ().startsWith ("2009-10-31" ));
369
+ }
370
+ finally {
371
+ TimeZone .setDefault (defaultZone );
372
+ }
365
373
}
366
374
367
375
@ Test
0 commit comments