@@ -97,19 +97,16 @@ public void testDateUtilISO8601_Timezone() throws Exception
97
97
// According to ISO8601, hours and minutes of the offset must be expressed with 2 digits
98
98
// (not more, not less), i.e. Z or +hh:mm or -hh:mm. See https://www.w3.org/TR/NOTE-datetime.
99
99
//
100
- // The forms below should be refused but some are accepted by the StdDateFormat. They are
101
- // included in the test to detect any change in behavior in futur releases...
100
+ // The forms below are therefore ILLEGAL and must be refused.
102
101
// ---------------------------------------------------------------------------------------------
103
102
104
- // Interpreted as if there was no timezone, therefore producing a date with the TZ set on the mapper
105
- // FIXME it is probably better to refuse these cases instead of silently creating dates in local tz...
106
- failure ( MAPPER , "2000-01-02T03:04:05.678+" ); // judate(2000, 1, 2, 3, 4, 5, 678, LOCAL_TZ));
107
- failure ( MAPPER , "2000-01-02T03:04:05.678+1" ); // judate(2000, 1, 2, 3, 4, 5, 678, LOCAL_TZ));
103
+ failure ( MAPPER , "2000-01-02T03:04:05.678+" );
104
+ failure ( MAPPER , "2000-01-02T03:04:05.678+1" );
108
105
109
- failure ( MAPPER , "2000-01-02T03:04:05.678+001" ); // judate(2000, 1, 2, 3, 4, 5, 678, LOCAL_TZ));
110
- failure ( MAPPER , "2000-01-02T03:04:05.678+00:" ); // judate(2000, 1, 2, 3, 4, 5, 678, LOCAL_TZ));
111
- failure ( MAPPER , "2000-01-02T03:04:05.678+00:001" ); // judate(2000, 1, 2, 3, 4, 5, 678, LOCAL_TZ));
112
- failure ( MAPPER , "2000-01-02T03:04:05.678+001:001" ); // judate(2000, 1, 2, 3, 4, 5, 678, LOCAL_TZ));
106
+ failure ( MAPPER , "2000-01-02T03:04:05.678+001" );
107
+ failure ( MAPPER , "2000-01-02T03:04:05.678+00:" );
108
+ failure ( MAPPER , "2000-01-02T03:04:05.678+00:001" );
109
+ failure ( MAPPER , "2000-01-02T03:04:05.678+001:001" );
113
110
114
111
failure ( MAPPER , "2000-01-02T03:04:05.678+1:" );
115
112
failure ( MAPPER , "2000-01-02T03:04:05.678+00:1" );
@@ -121,36 +118,30 @@ public void testDateUtilISO8601_Timezone() throws Exception
121
118
public void testDateUtilISO8601_DateTimeMillis () throws Exception
122
119
{
123
120
// WITH timezone (from 4 to 0 digits)
124
- verify ( MAPPER , "2000-01-02T03:04:05.678+01:00" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 678 , "GMT+1" ));
125
- verify ( MAPPER , "2000-01-02T03:04:05.67+01:00" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 670 , "GMT+1" ));
126
- verify ( MAPPER , "2000-01-02T03:04:05.6+01:00" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 600 , "GMT+1" ));
127
- verify ( MAPPER , "2000-01-02T03:04:05+01:00" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 000 , "GMT+1" ));
121
+ failure (MAPPER , "2000-01-02T03:04:05.0123456789+01:00" ); // at most 9 digits for the millis
122
+ verify ( MAPPER , "2000-01-02T03:04:05.6789+01:00" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 678 , "GMT+1" ));
123
+ verify ( MAPPER , "2000-01-02T03:04:05.678+01:00" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 678 , "GMT+1" ));
124
+ verify ( MAPPER , "2000-01-02T03:04:05.67+01:00" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 670 , "GMT+1" ));
125
+ verify ( MAPPER , "2000-01-02T03:04:05.6+01:00" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 600 , "GMT+1" ));
126
+ verify ( MAPPER , "2000-01-02T03:04:05+01:00" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 000 , "GMT+1" ));
128
127
129
128
130
- // failure(MAPPER, "2000-01-02T03:04:05.6789+01:00");
131
- // failure( MAPPER, "2000-01-02T03:04:05.6789Z"); // , judate(2000, 1, 2, 3, 4, 11, 789, "UTC"));
132
-
133
129
// WITH timezone Z (from 4 to 0 digits)
134
- // FIXME the .6789 millis are interpreted as 6789 millisecondes or 6.789 seconds!
135
- verify ( MAPPER , "2000-01-02T03:04:05.678Z" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 678 , "UTC" ));
136
- verify ( MAPPER , "2000-01-02T03:04:05.67Z" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 670 , "UTC" ));
137
- // FIXME should be 670 millis instead of 67
138
- verify ( MAPPER , "2000-01-02T03:04:05.6Z" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 600 , "UTC" ));
139
- // FIXME should be 600 millis instead of 6
140
- verify ( MAPPER , "2000-01-02T03:04:05Z" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 0 , "UTC" ));
130
+ failure (MAPPER , "2000-01-02T03:04:05.0123456789Z" ); // at most 9 digits for the millis
131
+ verify ( MAPPER , "2000-01-02T03:04:05.6789Z" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 678 , "UTC" ));
132
+ verify ( MAPPER , "2000-01-02T03:04:05.678Z" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 678 , "UTC" ));
133
+ verify ( MAPPER , "2000-01-02T03:04:05.67Z" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 670 , "UTC" ));
134
+ verify ( MAPPER , "2000-01-02T03:04:05.6Z" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 600 , "UTC" ));
135
+ verify ( MAPPER , "2000-01-02T03:04:05Z" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 0 , "UTC" ));
141
136
142
137
143
138
// WITHOUT timezone (from 4 to 0 digits)
144
- // FIXME: the .6789 millis are interpreted as 6789 millisecondes or 6.789 seconds!
145
-
146
- verify ( MAPPER , "2000-01-02T03:04:05.678" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 678 , LOCAL_TZ ));
147
- verify ( MAPPER , "2000-01-02T03:04:05.67" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 670 , LOCAL_TZ ));
148
- // FIXME: the .67 millis are interpreted as 67 seconds.
149
-
150
- verify ( MAPPER , "2000-01-02T03:04:05.6" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 600 , LOCAL_TZ ));
151
- verify ( MAPPER , "2000-01-02T03:04:05" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 000 , LOCAL_TZ ));
152
-
153
- // failure(MAPPER, "2000-01-02T03:04:05.6789"); // judate(2000, 1, 2, 3, 4, 11, 789, LOCAL_TZ));
139
+ failure (MAPPER , "2000-01-02T03:04:05.0123456789" ); // at most 9 digits for the millis
140
+ verify ( MAPPER , "2000-01-02T03:04:05.6789" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 678 , LOCAL_TZ ));
141
+ verify ( MAPPER , "2000-01-02T03:04:05.678" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 678 , LOCAL_TZ ));
142
+ verify ( MAPPER , "2000-01-02T03:04:05.67" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 670 , LOCAL_TZ ));
143
+ verify ( MAPPER , "2000-01-02T03:04:05.6" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 600 , LOCAL_TZ ));
144
+ verify ( MAPPER , "2000-01-02T03:04:05" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 000 , LOCAL_TZ ));
154
145
155
146
156
147
// ---------------------------------------------------------------------------------------------
@@ -165,17 +156,16 @@ public void testDateUtilISO8601_DateTimeMillis() throws Exception
165
156
// time-secfrac = "." 1*DIGIT
166
157
// partial-time = time-hour ":" time-minute ":" time-second [time-secfrac]
167
158
//
168
- // The second fraction (ie the millis) is optional and can be ommitted . However, a fraction
159
+ // The second fraction (ie the millis) is optional and can be omitted . However, a fraction
169
160
// with only a dot (.) and no digit is not allowed.
170
161
//
171
- // The forms below should be refused but some are accepted by the StdDateFormat. They are
172
- // included in the test to detect any change in behavior in futur releases...
162
+ // The forms below are therefore ILLEGAL and must be refused.
173
163
// ---------------------------------------------------------------------------------------------
174
164
175
165
// millis part with only a dot (.) and no digits
176
- failure ( MAPPER , "2000-01-02T03:04:05.+01:00" ); // judate(2000, 1, 2, 3, 4, 5, 000, "GMT+1"));
177
- failure ( MAPPER , "2000-01-02T03:04:05." ); // judate(2000, 1, 2, 3, 4, 5, 000, LOCAL_TZ));
178
- failure (MAPPER , "2000-01-02T03:04:05.Z" ); // FIXME this one fails, but not the others...
166
+ failure ( MAPPER , "2000-01-02T03:04:05.+01:00" );
167
+ failure ( MAPPER , "2000-01-02T03:04:05." );
168
+ failure ( MAPPER , "2000-01-02T03:04:05.Z" );
179
169
}
180
170
181
171
@@ -192,26 +182,24 @@ public void testDateUtilISO8601_DateTime() throws Exception
192
182
// No timezone --> the one configured on the ObjectMapper must be used
193
183
verify (MAPPER , "2000-01-02T03:04:05" , judate (2000 , 1 , 2 , 3 , 4 , 5 , 0 , LOCAL_TZ ));
194
184
195
- // Hours, minutes and seconds are mandatory when time is specified
185
+ // Hours, minutes are mandatory but seconds are optional
196
186
failure (MAPPER , "2000-01-02T" );
197
187
failure (MAPPER , "2000-01-02T03" );
198
188
failure (MAPPER , "2000-01-02T03:" );
199
189
verify (MAPPER , "2000-01-02T03:04" , judate (2000 , 1 , 2 , 3 , 4 , 0 , 0 , LOCAL_TZ ));
200
190
failure (MAPPER , "2000-01-02T03:04:" );
201
191
202
- // Although hours, minutes and seconds are mandatory, they can sometimes be omitted
203
- // if a TZ is specified... !!??
192
+ // Hours, minutes are mandatory but seconds are optional - test with a TZ
204
193
failure (MAPPER , "2000-01-02T+01:00" );
205
194
failure (MAPPER , "2000-01-02T03+01:00" );
206
195
failure (MAPPER , "2000-01-02T03:+01:00" );
207
- verify ( MAPPER , "2000-01-02T03:04+01:00" , judate (2000 , 1 , 2 , 3 , 4 , 0 , 0 , "GMT+1" )); // FIXME should be refused
196
+ verify ( MAPPER , "2000-01-02T03:04+01:00" , judate (2000 , 1 , 2 , 3 , 4 , 0 , 0 , "GMT+1" ));
208
197
failure (MAPPER , "2000-01-02T03:04:+01:00" );
209
198
210
199
failure (MAPPER , "2000-01-02TZ" );
211
200
failure (MAPPER , "2000-01-02T03Z" );
212
201
failure (MAPPER , "2000-01-02T03:Z" );
213
202
verify (MAPPER , "2000-01-02T03:04Z" , judate (2000 , 1 , 2 , 3 , 4 , 0 , 0 , "UTC" ));
214
-
215
203
failure (MAPPER , "2000-01-02T03:04:Z" );
216
204
217
205
@@ -233,8 +221,8 @@ public void testDateUtilISO8601_DateTime() throws Exception
233
221
// Behavior should be the SAME whatever the timezone and/or the millis.
234
222
235
223
// seconds (no TZ)
236
- failure ( MAPPER , "2000-01-02T03:04:5" ); // judate(2000, 1, 2, 3, 4, 5, 0, LOCAL_TZ));
237
- failure ( MAPPER , "2000-01-02T03:04:5.000" ); // judate(2000, 1, 2, 3, 4, 5, 0, LOCAL_TZ));
224
+ failure ( MAPPER , "2000-01-02T03:04:5" );
225
+ failure ( MAPPER , "2000-01-02T03:04:5.000" );
238
226
failure (MAPPER , "2000-01-02T03:04:005" );
239
227
240
228
// seconds (+01:00)
@@ -244,13 +232,13 @@ public void testDateUtilISO8601_DateTime() throws Exception
244
232
245
233
// seconds (Z)
246
234
failure (MAPPER , "2000-01-02T03:04:5Z" );
247
- failure ( MAPPER , "2000-01-02T03:04:5.000Z" ); // judate(2000, 1, 2, 3, 4, 5, 0, "UTC"));
235
+ failure ( MAPPER , "2000-01-02T03:04:5.000Z" );
248
236
failure (MAPPER , "2000-01-02T03:04:005Z" );
249
237
250
238
251
239
// minutes (no TZ)
252
- failure ( MAPPER , "2000-01-02T03:4:05" ); // judate(2000, 1, 2, 3, 4, 5, 0, LOCAL_TZ));
253
- failure ( MAPPER , "2000-01-02T03:4:05.000" ); // judate(2000, 1, 2, 3, 4, 5, 0, LOCAL_TZ));
240
+ failure ( MAPPER , "2000-01-02T03:4:05" );
241
+ failure ( MAPPER , "2000-01-02T03:4:05.000" );
254
242
failure (MAPPER , "2000-01-02T03:004:05" );
255
243
256
244
// minutes (+01:00)
@@ -259,13 +247,13 @@ public void testDateUtilISO8601_DateTime() throws Exception
259
247
failure (MAPPER , "2000-01-02T03:004:05+01:00" );
260
248
261
249
// minutes (Z)
262
- failure ( MAPPER , "2000-01-02T03:4:05Z" ); // judate(2000, 1, 2, 3, 4, 5, 0, "UTC"));
263
- failure ( MAPPER , "2000-01-02T03:4:05.000Z" ); // judate(2000, 1, 2, 3, 4, 5, 0, "UTC"));
264
- failure ( MAPPER , "2000-01-02T03:004:05Z" ); // judate(2000, 1, 2, 3, 4, 5, 0, "UTC"));
250
+ failure ( MAPPER , "2000-01-02T03:4:05Z" );
251
+ failure ( MAPPER , "2000-01-02T03:4:05.000Z" );
252
+ failure ( MAPPER , "2000-01-02T03:004:05Z" );
265
253
266
254
// hour (no TZ)
267
- failure ( MAPPER , "2000-01-02T3:04:05" ); // judate(2000, 1, 2, 3, 4, 5, 0, LOCAL_TZ));
268
- failure ( MAPPER , "2000-01-02T3:04:05.000" ); // judate(2000, 1, 2, 3, 4, 5, 0, LOCAL_TZ));
255
+ failure ( MAPPER , "2000-01-02T3:04:05" );
256
+ failure ( MAPPER , "2000-01-02T3:04:05.000" );
269
257
failure (MAPPER , "2000-01-02T003:04:05" );
270
258
271
259
// hour (+01:00)
@@ -274,9 +262,9 @@ public void testDateUtilISO8601_DateTime() throws Exception
274
262
failure (MAPPER , "2000-01-02T003:04:05+01:00" );
275
263
276
264
// hour (Z)
277
- failure ( MAPPER , "2000-01-02T3:04:05Z" ); // judate(2000, 1, 2, 3, 4, 5, 0, "UTC"));
278
- failure ( MAPPER , "2000-01-02T3:04:05.000Z" ); // judate(2000, 1, 2, 3, 4, 5, 0, "UTC"));
279
- failure ( MAPPER , "2000-01-02T003:04:05Z" ); // judate(2000, 1, 2, 3, 4, 5, 0, "UTC"));
265
+ failure ( MAPPER , "2000-01-02T3:04:05Z" );
266
+ failure ( MAPPER , "2000-01-02T3:04:05.000Z" );
267
+ failure ( MAPPER , "2000-01-02T003:04:05Z" );
280
268
}
281
269
282
270
/**
@@ -302,18 +290,18 @@ public void testDateUtilISO8601_Date() throws Exception
302
290
// ---------------------------------------------------------------------------------------------
303
291
304
292
// day
305
- failure ( MAPPER , "2000-01-2" ); // judate(2000, 1, 2, 0, 0, 0, 0, LOCAL_TZ));
293
+ failure ( MAPPER , "2000-01-2" );
306
294
failure ( MAPPER , "2000-01-002" );
307
295
308
296
// month
309
- failure ( MAPPER , "2000-1-02" ); // judate(2000, 1, 2, 0, 0, 0, 0, LOCAL_TZ) );
297
+ failure ( MAPPER , "2000-1-02" );
310
298
failure ( MAPPER , "2000-001-02" );
311
299
312
300
// year
313
301
failure ( MAPPER , "20000-01-02" );
314
302
failure ( MAPPER , "200-01-02" );
315
303
failure ( MAPPER , "20-01-02" );
316
- failure ( MAPPER , "2-01-02" ); // judate(2, 1, 2, 0, 0, 0, 0, LOCAL_TZ)); // FIXME Why accept 1 digit and refuse they other cases??
304
+ failure ( MAPPER , "2-01-02" );
317
305
}
318
306
319
307
/**
@@ -559,7 +547,6 @@ private static void failure(ObjectMapper mapper, Object input, Class<? extends E
559
547
catch (Exception e ) {
560
548
// Is it the expected exception ?
561
549
if (!exceptionType .isAssignableFrom (e .getClass ()) ) {
562
- e .printStackTrace ();
563
550
fail ("Wrong exception thrown when reading " +input +", actual: " +e .getClass ().getName () + "(" +e .getMessage ()+"), expected: " +exceptionType .getName ());
564
551
}
565
552
}
0 commit comments