-
-
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.
- Loading branch information
1 parent
615bf02
commit b744bf3
Showing
2 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
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
100 changes: 100 additions & 0 deletions
100
src/test/java/com/fasterxml/jackson/failing/TestDefaultForUtilCollections1868.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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import java.util.*; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.databind.BaseMapTest; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
// Unit tests for [databind#1868], related | ||
public class TestDefaultForUtilCollections1868 extends BaseMapTest | ||
{ | ||
private final ObjectMapper DEFAULT_MAPPER = new ObjectMapper(); | ||
{ | ||
DEFAULT_MAPPER.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY); | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Unit tests, "empty" types | ||
/********************************************************** | ||
*/ | ||
|
||
public void testEmptyList() throws Exception { | ||
_verifyCollection(Collections.emptyList()); | ||
} | ||
|
||
public void testEmptySet() throws Exception { | ||
_verifyCollection(Collections.emptySet()); | ||
} | ||
|
||
public void testEmptyMap() throws Exception { | ||
_verifyMap(Collections.emptyMap()); | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Unit tests, "singleton" types | ||
/********************************************************** | ||
*/ | ||
|
||
public void testSingletonList() throws Exception { | ||
_verifyCollection(Collections.singletonList(Arrays.asList("TheOne"))); | ||
} | ||
|
||
public void testSingletonSet() throws Exception { | ||
_verifyCollection(Collections.singleton(Arrays.asList("TheOne"))); | ||
} | ||
|
||
public void testSingletonMap() throws Exception { | ||
_verifyMap(Collections.singletonMap("foo", "bar")); | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Unit tests, "unmodifiable" types | ||
/********************************************************** | ||
*/ | ||
|
||
public void testUnmodifiableList() throws Exception { | ||
_verifyCollection(Collections.unmodifiableList(Arrays.asList("first", "second"))); | ||
} | ||
|
||
public void testUnmodifiableSet() throws Exception | ||
{ | ||
Set<String> input = new LinkedHashSet<>(Arrays.asList("first", "second")); | ||
_verifyCollection(Collections.unmodifiableSet(input)); | ||
} | ||
|
||
public void testUnmodifiableMap() throws Exception | ||
{ | ||
Map<String,String> input = new LinkedHashMap<>(); | ||
input.put("a", "b"); | ||
input.put("c", "d"); | ||
_verifyMap(Collections.unmodifiableMap(input)); | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Helper methods | ||
/********************************************************** | ||
*/ | ||
|
||
protected void _verifyCollection(Collection<?> exp) throws Exception | ||
{ | ||
String json = DEFAULT_MAPPER.writeValueAsString(exp); | ||
Collection<?> act = DEFAULT_MAPPER.readValue(json, Collection.class); | ||
|
||
assertEquals(exp, act); | ||
assertEquals(exp.getClass(), act.getClass()); | ||
} | ||
|
||
protected void _verifyMap(Map<?,?> exp) throws Exception | ||
{ | ||
String json = DEFAULT_MAPPER.writeValueAsString(exp); | ||
Map<?,?> act = DEFAULT_MAPPER.readValue(json, Map.class); | ||
|
||
assertEquals(exp, act); | ||
assertEquals(exp.getClass(), act.getClass()); | ||
} | ||
} |