45
45
*/
46
46
public class DateFormattingTests {
47
47
48
- private final FormattingConversionService conversionService = new FormattingConversionService () ;
48
+ private FormattingConversionService conversionService ;
49
49
50
50
private DataBinder binder ;
51
51
52
52
53
53
@ BeforeEach
54
- public void setup () {
54
+ void setup () {
55
55
DateFormatterRegistrar registrar = new DateFormatterRegistrar ();
56
56
setup (registrar );
57
57
}
58
58
59
59
private void setup (DateFormatterRegistrar registrar ) {
60
+ conversionService = new FormattingConversionService ();
60
61
DefaultConversionService .addDefaultConverters (conversionService );
61
62
registrar .registerFormatters (conversionService );
62
63
@@ -69,13 +70,13 @@ private void setup(DateFormatterRegistrar registrar) {
69
70
}
70
71
71
72
@ AfterEach
72
- public void tearDown () {
73
+ void tearDown () {
73
74
LocaleContextHolder .setLocale (null );
74
75
}
75
76
76
77
77
78
@ Test
78
- public void testBindLong () {
79
+ void testBindLong () {
79
80
MutablePropertyValues propertyValues = new MutablePropertyValues ();
80
81
propertyValues .add ("millis" , "1256961600" );
81
82
binder .bind (propertyValues );
@@ -84,7 +85,7 @@ public void testBindLong() {
84
85
}
85
86
86
87
@ Test
87
- public void testBindLongAnnotated () {
88
+ void testBindLongAnnotated () {
88
89
MutablePropertyValues propertyValues = new MutablePropertyValues ();
89
90
propertyValues .add ("millisAnnotated" , "10/31/09" );
90
91
binder .bind (propertyValues );
@@ -93,7 +94,7 @@ public void testBindLongAnnotated() {
93
94
}
94
95
95
96
@ Test
96
- public void testBindCalendarAnnotated () {
97
+ void testBindCalendarAnnotated () {
97
98
MutablePropertyValues propertyValues = new MutablePropertyValues ();
98
99
propertyValues .add ("calendarAnnotated" , "10/31/09" );
99
100
binder .bind (propertyValues );
@@ -102,7 +103,7 @@ public void testBindCalendarAnnotated() {
102
103
}
103
104
104
105
@ Test
105
- public void testBindDateAnnotated () {
106
+ void testBindDateAnnotated () {
106
107
MutablePropertyValues propertyValues = new MutablePropertyValues ();
107
108
propertyValues .add ("dateAnnotated" , "10/31/09" );
108
109
binder .bind (propertyValues );
@@ -111,15 +112,15 @@ public void testBindDateAnnotated() {
111
112
}
112
113
113
114
@ Test
114
- public void testBindDateArray () {
115
+ void testBindDateArray () {
115
116
MutablePropertyValues propertyValues = new MutablePropertyValues ();
116
117
propertyValues .add ("dateAnnotated" , new String []{"10/31/09 12:00 PM" });
117
118
binder .bind (propertyValues );
118
119
assertThat (binder .getBindingResult ().getErrorCount ()).isEqualTo (0 );
119
120
}
120
121
121
122
@ Test
122
- public void testBindDateAnnotatedWithError () {
123
+ void testBindDateAnnotatedWithError () {
123
124
MutablePropertyValues propertyValues = new MutablePropertyValues ();
124
125
propertyValues .add ("dateAnnotated" , "Oct X31, 2009" );
125
126
binder .bind (propertyValues );
@@ -129,7 +130,7 @@ public void testBindDateAnnotatedWithError() {
129
130
130
131
@ Test
131
132
@ Disabled
132
- public void testBindDateAnnotatedWithFallbackError () {
133
+ void testBindDateAnnotatedWithFallbackError () {
133
134
// TODO This currently passes because of the Date(String) constructor fallback is used
134
135
MutablePropertyValues propertyValues = new MutablePropertyValues ();
135
136
propertyValues .add ("dateAnnotated" , "Oct 031, 2009" );
@@ -139,7 +140,7 @@ public void testBindDateAnnotatedWithFallbackError() {
139
140
}
140
141
141
142
@ Test
142
- public void testBindDateAnnotatedPattern () {
143
+ void testBindDateAnnotatedPattern () {
143
144
MutablePropertyValues propertyValues = new MutablePropertyValues ();
144
145
propertyValues .add ("dateAnnotatedPattern" , "10/31/09 1:05" );
145
146
binder .bind (propertyValues );
@@ -148,15 +149,29 @@ public void testBindDateAnnotatedPattern() {
148
149
}
149
150
150
151
@ Test
151
- public void testBindDateTimeOverflow () {
152
+ void testBindDateAnnotatedPatternWithGlobalFormat () {
153
+ DateFormatterRegistrar registrar = new DateFormatterRegistrar ();
154
+ DateFormatter dateFormatter = new DateFormatter ();
155
+ dateFormatter .setIso (ISO .DATE_TIME );
156
+ registrar .setFormatter (dateFormatter );
157
+ setup (registrar );
158
+ MutablePropertyValues propertyValues = new MutablePropertyValues ();
159
+ propertyValues .add ("dateAnnotatedPattern" , "10/31/09 1:05" );
160
+ binder .bind (propertyValues );
161
+ assertThat (binder .getBindingResult ().getErrorCount ()).isEqualTo (0 );
162
+ assertThat (binder .getBindingResult ().getFieldValue ("dateAnnotatedPattern" )).isEqualTo ("10/31/09 1:05" );
163
+ }
164
+
165
+ @ Test
166
+ void testBindDateTimeOverflow () {
152
167
MutablePropertyValues propertyValues = new MutablePropertyValues ();
153
168
propertyValues .add ("dateAnnotatedPattern" , "02/29/09 12:00 PM" );
154
169
binder .bind (propertyValues );
155
170
assertThat (binder .getBindingResult ().getErrorCount ()).isEqualTo (1 );
156
171
}
157
172
158
173
@ Test
159
- public void testBindISODate () {
174
+ void testBindISODate () {
160
175
MutablePropertyValues propertyValues = new MutablePropertyValues ();
161
176
propertyValues .add ("isoDate" , "2009-10-31" );
162
177
binder .bind (propertyValues );
@@ -165,7 +180,7 @@ public void testBindISODate() {
165
180
}
166
181
167
182
@ Test
168
- public void testBindISOTime () {
183
+ void testBindISOTime () {
169
184
MutablePropertyValues propertyValues = new MutablePropertyValues ();
170
185
propertyValues .add ("isoTime" , "12:00:00.000-05:00" );
171
186
binder .bind (propertyValues );
@@ -174,7 +189,7 @@ public void testBindISOTime() {
174
189
}
175
190
176
191
@ Test
177
- public void testBindISODateTime () {
192
+ void testBindISODateTime () {
178
193
MutablePropertyValues propertyValues = new MutablePropertyValues ();
179
194
propertyValues .add ("isoDateTime" , "2009-10-31T12:00:00.000-08:00" );
180
195
binder .bind (propertyValues );
@@ -183,7 +198,7 @@ public void testBindISODateTime() {
183
198
}
184
199
185
200
@ Test
186
- public void testBindNestedDateAnnotated () {
201
+ void testBindNestedDateAnnotated () {
187
202
MutablePropertyValues propertyValues = new MutablePropertyValues ();
188
203
propertyValues .add ("children[0].dateAnnotated" , "10/31/09" );
189
204
binder .bind (propertyValues );
@@ -192,15 +207,15 @@ public void testBindNestedDateAnnotated() {
192
207
}
193
208
194
209
@ Test
195
- public void dateToStringWithoutGlobalFormat () {
210
+ void dateToStringWithoutGlobalFormat () {
196
211
Date date = new Date ();
197
212
Object actual = this .conversionService .convert (date , TypeDescriptor .valueOf (Date .class ), TypeDescriptor .valueOf (String .class ));
198
213
String expected = date .toString ();
199
214
assertThat (actual ).isEqualTo (expected );
200
215
}
201
216
202
217
@ Test
203
- public void dateToStringWithGlobalFormat () {
218
+ void dateToStringWithGlobalFormat () {
204
219
DateFormatterRegistrar registrar = new DateFormatterRegistrar ();
205
220
registrar .setFormatter (new DateFormatter ());
206
221
setup (registrar );
@@ -212,14 +227,14 @@ public void dateToStringWithGlobalFormat() {
212
227
213
228
@ Test // SPR-10105
214
229
@ SuppressWarnings ("deprecation" )
215
- public void stringToDateWithoutGlobalFormat () {
230
+ void stringToDateWithoutGlobalFormat () {
216
231
String string = "Sat, 12 Aug 1995 13:30:00 GM" ;
217
232
Date date = this .conversionService .convert (string , Date .class );
218
233
assertThat (date ).isEqualTo (new Date (string ));
219
234
}
220
235
221
236
@ Test // SPR-10105
222
- public void stringToDateWithGlobalFormat () {
237
+ void stringToDateWithGlobalFormat () {
223
238
DateFormatterRegistrar registrar = new DateFormatterRegistrar ();
224
239
DateFormatter dateFormatter = new DateFormatter ();
225
240
dateFormatter .setIso (ISO .DATE_TIME );
0 commit comments