Skip to content

Commit

Permalink
Minor rewrite of test from #4012, to easy merge to master
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 5, 2023
1 parent 644a742 commit badad56
Showing 1 changed file with 10 additions and 31 deletions.
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("\"\""));
}
}

0 comments on commit badad56

Please sign in to comment.