Skip to content

Commit 98467e7

Browse files
committed
refactor mapper construction to make merging easier
1 parent 8cde8aa commit 98467e7

File tree

1 file changed

+17
-32
lines changed

1 file changed

+17
-32
lines changed

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

+17-32
Original file line numberDiff line numberDiff line change
@@ -438,21 +438,15 @@ public void testStrictDeserializeFromEmptyString() throws Exception {
438438

439439
@Test
440440
public void shouldDeserializeInNanos_whenNanosUnitAsPattern_andValueIsInteger() throws Exception {
441-
ObjectMapper mapper = newMapper();
442-
mapper.configOverride(Duration.class)
443-
.setFormat(JsonFormat.Value.forPattern("NANOS"));
441+
ObjectMapper mapper = _mapperForPatternOverride("NANOS");
444442
ObjectReader reader = mapper.readerFor(MAP_TYPE_REF);
445-
446443
Wrapper wrapper = reader.readValue(wrapperPayload(25), Wrapper.class);
447-
448444
assertEquals(Duration.ofNanos(25), wrapper.value);
449445
}
450446

451447
@Test
452448
public void shouldDeserializeInMicros_whenMicrosUnitAsPattern_andValueIsInteger() throws Exception {
453-
ObjectMapper mapper = newMapper();
454-
mapper.configOverride(Duration.class)
455-
.setFormat(JsonFormat.Value.forPattern("MICROS"));
449+
ObjectMapper mapper = _mapperForPatternOverride("MICROS");
456450
ObjectReader reader = mapper.readerFor(MAP_TYPE_REF);
457451

458452
Wrapper wrapper = reader.readValue(wrapperPayload(25), Wrapper.class);
@@ -462,9 +456,7 @@ public void shouldDeserializeInMicros_whenMicrosUnitAsPattern_andValueIsInteger(
462456

463457
@Test
464458
public void shouldDeserializeInMillis_whenMillisUnitAsPattern_andValueIsInteger() throws Exception {
465-
ObjectMapper mapper = newMapper();
466-
mapper.configOverride(Duration.class)
467-
.setFormat(JsonFormat.Value.forPattern("MILLIS"));
459+
ObjectMapper mapper = _mapperForPatternOverride("MILLIS");
468460
ObjectReader reader = mapper.readerFor(MAP_TYPE_REF);
469461

470462
Wrapper wrapper = reader.readValue(wrapperPayload(25), Wrapper.class);
@@ -474,9 +466,7 @@ public void shouldDeserializeInMillis_whenMillisUnitAsPattern_andValueIsInteger(
474466

475467
@Test
476468
public void shouldDeserializeInSeconds_whenSecondsUnitAsPattern_andValueIsInteger() throws Exception {
477-
ObjectMapper mapper = newMapper();
478-
mapper.configOverride(Duration.class)
479-
.setFormat(JsonFormat.Value.forPattern("SECONDS"));
469+
ObjectMapper mapper = _mapperForPatternOverride("SECONDS");
480470
ObjectReader reader = mapper.readerFor(MAP_TYPE_REF);
481471

482472
Wrapper wrapper = reader.readValue(wrapperPayload(25), Wrapper.class);
@@ -486,9 +476,7 @@ public void shouldDeserializeInSeconds_whenSecondsUnitAsPattern_andValueIsIntege
486476

487477
@Test
488478
public void shouldDeserializeInMinutes_whenMinutesUnitAsPattern_andValueIsInteger() throws Exception {
489-
ObjectMapper mapper = newMapper();
490-
mapper.configOverride(Duration.class)
491-
.setFormat(JsonFormat.Value.forPattern("MINUTES"));
479+
ObjectMapper mapper = _mapperForPatternOverride("MINUTES");
492480
ObjectReader reader = mapper.readerFor(MAP_TYPE_REF);
493481

494482
Wrapper wrapper = reader.readValue(wrapperPayload(25), Wrapper.class);
@@ -498,9 +486,7 @@ public void shouldDeserializeInMinutes_whenMinutesUnitAsPattern_andValueIsIntege
498486

499487
@Test
500488
public void shouldDeserializeInHours_whenHoursUnitAsPattern_andValueIsInteger() throws Exception {
501-
ObjectMapper mapper = newMapper();
502-
mapper.configOverride(Duration.class)
503-
.setFormat(JsonFormat.Value.forPattern("HOURS"));
489+
ObjectMapper mapper = _mapperForPatternOverride("HOURS");
504490
ObjectReader reader = mapper.readerFor(MAP_TYPE_REF);
505491

506492
Wrapper wrapper = reader.readValue(wrapperPayload(25), Wrapper.class);
@@ -510,9 +496,7 @@ public void shouldDeserializeInHours_whenHoursUnitAsPattern_andValueIsInteger()
510496

511497
@Test
512498
public void shouldDeserializeInHalfDays_whenHalfDaysUnitAsPattern_andValueIsInteger() throws Exception {
513-
ObjectMapper mapper = newMapper();
514-
mapper.configOverride(Duration.class)
515-
.setFormat(JsonFormat.Value.forPattern("HALF_DAYS"));
499+
ObjectMapper mapper = _mapperForPatternOverride("HALF_DAYS");
516500
ObjectReader reader = mapper.readerFor(MAP_TYPE_REF);
517501

518502
Wrapper wrapper = reader.readValue(wrapperPayload(25), Wrapper.class);
@@ -522,9 +506,7 @@ public void shouldDeserializeInHalfDays_whenHalfDaysUnitAsPattern_andValueIsInte
522506

523507
@Test
524508
public void shouldDeserializeInDays_whenDaysUnitAsPattern_andValueIsInteger() throws Exception {
525-
ObjectMapper mapper = newMapper();
526-
mapper.configOverride(Duration.class)
527-
.setFormat(JsonFormat.Value.forPattern("DAYS"));
509+
ObjectMapper mapper = _mapperForPatternOverride("DAYS");
528510
ObjectReader reader = mapper.readerFor(MAP_TYPE_REF);
529511

530512
Wrapper wrapper = reader.readValue(wrapperPayload(25), Wrapper.class);
@@ -534,9 +516,7 @@ public void shouldDeserializeInDays_whenDaysUnitAsPattern_andValueIsInteger() th
534516

535517
@Test
536518
public void shouldIgnoreUnitPattern_whenValueIsFloat() throws Exception {
537-
ObjectMapper mapper = newMapper();
538-
mapper.configOverride(Duration.class)
539-
.setFormat(JsonFormat.Value.forPattern("MINUTES"));
519+
ObjectMapper mapper = _mapperForPatternOverride("MINUTES");
540520
ObjectReader reader = mapper.readerFor(MAP_TYPE_REF);
541521

542522
Wrapper wrapper = reader.readValue(wrapperPayload(25.5), Wrapper.class);
@@ -546,9 +526,7 @@ public void shouldIgnoreUnitPattern_whenValueIsFloat() throws Exception {
546526

547527
@Test
548528
public void shouldIgnoreUnitPattern_whenValueIsString() throws Exception {
549-
ObjectMapper mapper = newMapper();
550-
mapper.configOverride(Duration.class)
551-
.setFormat(JsonFormat.Value.forPattern("MINUTES"));
529+
ObjectMapper mapper = _mapperForPatternOverride("MINUTES");
552530
ObjectReader reader = mapper.readerFor(MAP_TYPE_REF);
553531

554532
Wrapper wrapper = reader.readValue("{\"value\":\"PT25S\"}", Wrapper.class);
@@ -575,4 +553,11 @@ public void shouldFailForInvalidPattern() throws Exception {
575553
private String wrapperPayload(Number number) {
576554
return "{\"value\":" + number + "}";
577555
}
556+
557+
private ObjectMapper _mapperForPatternOverride(String patternStr) {
558+
ObjectMapper mapper = newMapper();
559+
mapper.configOverride(Duration.class)
560+
.setFormat(JsonFormat.Value.forPattern(patternStr));
561+
return mapper;
562+
}
578563
}

0 commit comments

Comments
 (0)