Skip to content

Commit fad2545

Browse files
committed
Cleaning up test cases (mapper->builder/reader)
1 parent 5a91263 commit fad2545

File tree

1 file changed

+35
-57
lines changed

1 file changed

+35
-57
lines changed

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/OffsetDateTimeDeserTest.java

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,10 @@ public void testDeserializationAsInt03MillisecondsWithTimeZone() throws Exceptio
305305
public void testDeserializationAsString01WithoutTimeZone() throws Exception
306306
{
307307
OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochSecond(0L), Z1);
308+
ObjectReader r = MAPPER.readerFor(OffsetDateTime.class)
309+
.with(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
310+
OffsetDateTime value = r.readValue('"' + FORMATTER.format(date) + '"');
308311

309-
ObjectMapper m = newMapper()
310-
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
311-
OffsetDateTime value = m.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
312-
313-
assertNotNull("The value should not be null.", value);
314312
assertIsEqual(date, value);
315313
assertEquals("The time zone is not correct.", ZoneOffset.UTC, value.getOffset());
316314
}
@@ -319,12 +317,11 @@ public void testDeserializationAsString01WithoutTimeZone() throws Exception
319317
public void testDeserializationAsString01WithTimeZone() throws Exception
320318
{
321319
OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochSecond(0L), Z1);
322-
ObjectMapper m = newMapper()
323-
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true)
324-
.setTimeZone(TimeZone.getDefault());
325-
OffsetDateTime value = m.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
320+
ObjectReader r = MAPPER.readerFor(OffsetDateTime.class)
321+
.with(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
322+
.with(TimeZone.getDefault());
323+
OffsetDateTime value = r.readValue('"' + FORMATTER.format(date) + '"');
326324

327-
assertNotNull("The value should not be null.", value);
328325
assertIsEqual(date, value);
329326
assertEquals("The time zone is not correct.", getDefaultOffset(date), value.getOffset());
330327
}
@@ -333,12 +330,11 @@ public void testDeserializationAsString01WithTimeZone() throws Exception
333330
public void testDeserializationAsString01WithTimeZoneTurnedOff() throws Exception
334331
{
335332
OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochSecond(0L), Z1);
336-
ObjectMapper m = newMapper()
337-
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false)
338-
.setTimeZone(TimeZone.getDefault());
339-
OffsetDateTime value = m.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
333+
ObjectReader r = MAPPER.readerFor(OffsetDateTime.class)
334+
.without(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
335+
.with(TimeZone.getDefault());
336+
OffsetDateTime value = r.readValue('"' + FORMATTER.format(date) + '"');
340337

341-
assertNotNull("The value should not be null.", value);
342338
assertIsEqual(date, value);
343339
assertEquals("The time zone is not correct.", getOffset(value, Z1), value.getOffset());
344340
}
@@ -347,14 +343,12 @@ public void testDeserializationAsString01WithTimeZoneTurnedOff() throws Exceptio
347343
public void testDeserializationAsString01WithTimeZoneColonless() throws Exception
348344
{
349345
OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochSecond(0L), Z1);
350-
ObjectMapper m = newMapper()
351-
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
346+
ObjectReader r = MAPPER.readerFor(OffsetDateTime.class)
347+
.without(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
352348

353349
String sDate = offsetWithoutColon(FORMATTER.format(date));
350+
OffsetDateTime value = r.readValue('"' + sDate + '"');
354351

355-
OffsetDateTime value = m.readValue('"' + sDate + '"', OffsetDateTime.class);
356-
357-
assertNotNull("The value should not be null.", value);
358352
assertIsEqual(date, value);
359353
assertEquals("The time zone is not correct.", getOffset(value, Z1), value.getOffset());
360354
}
@@ -363,11 +357,10 @@ public void testDeserializationAsString01WithTimeZoneColonless() throws Exceptio
363357
public void testDeserializationAsString02WithoutTimeZone() throws Exception
364358
{
365359
OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), Z2);
366-
ObjectMapper m = newMapper()
367-
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
368-
OffsetDateTime value = m.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
360+
ObjectReader r = MAPPER.readerFor(OffsetDateTime.class)
361+
.with(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
362+
OffsetDateTime value = r.readValue('"' + FORMATTER.format(date) + '"');
369363

370-
assertNotNull("The value should not be null.", value);
371364
assertIsEqual(date, value);
372365
assertEquals("The time zone is not correct.", ZoneOffset.UTC, value.getOffset());
373366
}
@@ -376,12 +369,11 @@ public void testDeserializationAsString02WithoutTimeZone() throws Exception
376369
public void testDeserializationAsString02WithTimeZone() throws Exception
377370
{
378371
OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), Z2);
379-
ObjectMapper m = newMapper()
380-
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true)
381-
.setTimeZone(TimeZone.getDefault());
382-
OffsetDateTime value = m.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
372+
ObjectReader r = MAPPER.readerFor(OffsetDateTime.class)
373+
.with(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
374+
.with(TimeZone.getDefault());
375+
OffsetDateTime value = r.readValue('"' + FORMATTER.format(date) + '"');
383376

384-
assertNotNull("The value should not be null.", value);
385377
assertIsEqual(date, value);
386378
assertEquals("The time zone is not correct.", getDefaultOffset(date), value.getOffset());
387379
}
@@ -420,11 +412,10 @@ public void testDeserializationAsString02WithTimeZoneColonless() throws Exceptio
420412
public void testDeserializationAsString03WithoutTimeZone() throws Exception
421413
{
422414
OffsetDateTime date = OffsetDateTime.now(Z3);
423-
ObjectMapper m = newMapper()
424-
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
425-
OffsetDateTime value = m.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
415+
ObjectReader r = MAPPER.readerFor(OffsetDateTime.class)
416+
.with(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
417+
OffsetDateTime value = r.readValue('"' + FORMATTER.format(date) + '"');
426418

427-
assertNotNull("The value should not be null.", value);
428419
assertIsEqual(date, value);
429420
assertEquals("The time zone is not correct.", ZoneOffset.UTC, value.getOffset());
430421
}
@@ -433,12 +424,11 @@ public void testDeserializationAsString03WithoutTimeZone() throws Exception
433424
public void testDeserializationAsString03WithTimeZone() throws Exception
434425
{
435426
OffsetDateTime date = OffsetDateTime.now(Z3);
436-
ObjectMapper m = newMapper()
437-
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true)
438-
.setTimeZone(TimeZone.getDefault());
439-
OffsetDateTime value = m.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
427+
ObjectReader r = MAPPER.readerFor(OffsetDateTime.class)
428+
.with(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
429+
.with(TimeZone.getDefault());
430+
OffsetDateTime value = r.readValue('"' + FORMATTER.format(date) + '"');
440431

441-
assertNotNull("The value should not be null.", value);
442432
assertIsEqual(date, value);
443433
assertEquals("The time zone is not correct.", getDefaultOffset(date), value.getOffset());
444434
}
@@ -447,12 +437,11 @@ public void testDeserializationAsString03WithTimeZone() throws Exception
447437
public void testDeserializationAsString03WithTimeZoneTurnedOff() throws Exception
448438
{
449439
OffsetDateTime date = OffsetDateTime.now(Z3);
450-
ObjectMapper m = newMapper()
451-
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false)
452-
.setTimeZone(TimeZone.getDefault());
453-
OffsetDateTime value = m.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
440+
ObjectReader r = MAPPER.readerFor(OffsetDateTime.class)
441+
.without(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
442+
.with(TimeZone.getDefault());
443+
OffsetDateTime value = r.readValue('"' + FORMATTER.format(date) + '"');
454444

455-
assertNotNull("The value should not be null.", value);
456445
assertIsEqual(date, value);
457446
assertEquals("The time zone is not correct.", getOffset(value, Z3), value.getOffset());
458447
}
@@ -462,14 +451,12 @@ public void testDeserializationAsString03WithTimeZoneTurnedOff() throws Exceptio
462451
public void testDeserializationAsString03WithTimeZoneColonless() throws Exception
463452
{
464453
OffsetDateTime date = OffsetDateTime.now(Z3);
465-
ObjectMapper m = newMapper()
466-
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
467-
454+
ObjectReader r = MAPPER.readerFor(OffsetDateTime.class)
455+
.without(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
468456
String sDate = offsetWithoutColon(FORMATTER.format(date));
469457

470-
OffsetDateTime value = m.readValue('"' + sDate + '"', OffsetDateTime.class);
458+
OffsetDateTime value = r.readValue('"' + sDate + '"');
471459

472-
assertNotNull("The value should not be null.", value);
473460
assertIsEqual(date, value);
474461
assertEquals("The time zone is not correct.", getOffset(value, Z3), value.getOffset());
475462
}
@@ -484,7 +471,6 @@ public void testDeserializationWithTypeInfo01WithoutTimeZone() throws Exception
484471
"[\"" + OffsetDateTime.class.getName() + "\",123456789.183917322]", Temporal.class
485472
);
486473

487-
assertNotNull("The value should not be null.", value);
488474
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
489475
assertIsEqual(date, (OffsetDateTime) value);
490476
assertEquals("The time zone is not correct.", ZoneOffset.UTC, ((OffsetDateTime) value).getOffset());
@@ -501,7 +487,6 @@ public void testDeserializationWithTypeInfo01WithTimeZone() throws Exception
501487
"[\"" + OffsetDateTime.class.getName() + "\",123456789.183917322]", Temporal.class
502488
);
503489

504-
assertNotNull("The value should not be null.", value);
505490
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
506491
assertIsEqual(date, (OffsetDateTime) value);
507492
assertEquals("The time zone is not correct.", getDefaultOffset(date), ((OffsetDateTime) value).getOffset());
@@ -518,7 +503,6 @@ public void testDeserializationWithTypeInfo02WithoutTimeZone() throws Exception
518503
"[\"" + OffsetDateTime.class.getName() + "\",123456789]", Temporal.class
519504
);
520505

521-
assertNotNull("The value should not be null.", value);
522506
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
523507
assertIsEqual(date, (OffsetDateTime) value);
524508
assertEquals("The time zone is not correct.", ZoneOffset.UTC, ((OffsetDateTime) value).getOffset());
@@ -536,7 +520,6 @@ public void testDeserializationWithTypeInfo02WithTimeZone() throws Exception
536520
"[\"" + OffsetDateTime.class.getName() + "\",123456789]", Temporal.class
537521
);
538522

539-
assertNotNull("The value should not be null.", value);
540523
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
541524
assertIsEqual(date, (OffsetDateTime) value);
542525
assertEquals("The time zone is not correct.", getDefaultOffset(date), ((OffsetDateTime) value).getOffset());
@@ -553,7 +536,6 @@ public void testDeserializationWithTypeInfo03WithoutTimeZone() throws Exception
553536
"[\"" + OffsetDateTime.class.getName() + "\",123456789422]", Temporal.class
554537
);
555538

556-
assertNotNull("The value should not be null.", value);
557539
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
558540
assertIsEqual(date, (OffsetDateTime) value);
559541
assertEquals("The time zone is not correct.", ZoneOffset.UTC, ((OffsetDateTime) value).getOffset());
@@ -571,7 +553,6 @@ public void testDeserializationWithTypeInfo03WithTimeZone() throws Exception
571553
"[\"" + OffsetDateTime.class.getName() + "\",123456789422]", Temporal.class
572554
);
573555

574-
assertNotNull("The value should not be null.", value);
575556
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
576557
assertIsEqual(date, (OffsetDateTime) value);
577558
assertEquals("The time zone is not correct.", getDefaultOffset(date), ((OffsetDateTime) value).getOffset());
@@ -588,7 +569,6 @@ public void testDeserializationWithTypeInfo04WithoutTimeZone() throws Exception
588569
"[\"" + OffsetDateTime.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", Temporal.class
589570
);
590571

591-
assertNotNull("The value should not be null.", value);
592572
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
593573
assertIsEqual(date, (OffsetDateTime) value);
594574
assertEquals("The time zone is not correct.", ZoneOffset.UTC, ((OffsetDateTime) value).getOffset());
@@ -606,7 +586,6 @@ public void testDeserializationWithTypeInfo04WithTimeZone() throws Exception
606586
"[\"" + OffsetDateTime.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", Temporal.class
607587
);
608588

609-
assertNotNull("The value should not be null.", value);
610589
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
611590
assertIsEqual(date, (OffsetDateTime) value);
612591
assertEquals("The time zone is not correct.", getDefaultOffset(date), ((OffsetDateTime) value).getOffset());
@@ -625,7 +604,6 @@ public void testDeserializationWithTypeInfo04WithTimeZoneTurnedOff() throws Exce
625604
"[\"" + OffsetDateTime.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", Temporal.class
626605
);
627606

628-
assertNotNull("The value should not be null.", value);
629607
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
630608
OffsetDateTime cast = (OffsetDateTime) value;
631609
assertIsEqual(date, cast);

0 commit comments

Comments
 (0)