From badad566edcfb91dfb4c2ba7e2d20b23520e6f6c Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 4 Jul 2023 17:17:34 -0700 Subject: [PATCH] Minor rewrite of test from #4012, to easy merge to master --- .../deser/jdk/LocaleDeser4009Test.java | 41 +++++-------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/jdk/LocaleDeser4009Test.java b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/LocaleDeser4009Test.java index 7c73c58615..1f7e65ef5f 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/jdk/LocaleDeser4009Test.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/LocaleDeser4009Test.java @@ -1,47 +1,26 @@ package com.fasterxml.jackson.databind.deser.jdk; -import static org.junit.jupiter.api.Assertions.assertThrows; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.BaseMapTest; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectReader; import java.util.Locale; +import com.fasterxml.jackson.databind.*; + // [databind#4009] Locale "" is deserialised as NULL if ACCEPT_EMPTY_STRING_AS_NULL_OBJECT is true public class LocaleDeser4009Test extends BaseMapTest { - - static class MyPojo { - public String field; - } - final ObjectMapper mapper = newJsonMapper(); - - final ObjectReader DISABLED_READER = mapper.reader() - .without(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); - - final ObjectReader ENABLED_READER = mapper.reader() - .with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); - - public void testPOJOWithFeatureDisabled() - { - assertThrows(JsonProcessingException.class, () -> { - DISABLED_READER.readValue("\"\"", MyPojo.class); - }); - } - - public void testPOJOWithFeatureEnabled() throws Exception - { - assertNull(ENABLED_READER.readValue("\"\"", MyPojo.class)); - } + private final ObjectMapper MAPPER = newJsonMapper(); public void testLocaleWithFeatureDisabled() throws Exception { - assertEquals(Locale.ROOT, DISABLED_READER.readValue("\"\"", Locale.class)); + assertEquals(Locale.ROOT, + MAPPER.readerFor(Locale.class) + .without(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT) + .readValue("\"\"")); } public void testLocaleWithFeatureEnabled() throws Exception { - assertNull(ENABLED_READER.readValue("\"\"", Locale.class)); + assertNull(MAPPER.readerFor(Locale.class) + .with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT) + .readValue("\"\"")); } }