-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor rewrite of test from #4012, to easy merge to master
- Loading branch information
1 parent
644a742
commit badad56
Showing
1 changed file
with
10 additions
and
31 deletions.
There are no files selected for viewing
41 changes: 10 additions & 31 deletions
41
src/test/java/com/fasterxml/jackson/databind/deser/jdk/LocaleDeser4009Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("\"\"")); | ||
} | ||
} |