|
6 | 6 | import com.fasterxml.jackson.databind.BaseMapTest;
|
7 | 7 | import com.fasterxml.jackson.databind.ObjectMapper;
|
8 | 8 |
|
9 |
| -// Unit tests for [databind#1868], related |
10 |
| -public class TestDefaultForUtilCollections1868 extends BaseMapTest |
| 9 | +// Unit tests for [databind#1868], [databind#1880], [databind#2265] |
| 10 | +public class UtilCollectionsTypesTest extends BaseMapTest |
11 | 11 | {
|
12 | 12 | private final ObjectMapper DEFAULT_MAPPER = new ObjectMapper();
|
13 | 13 | {
|
@@ -60,6 +60,21 @@ public void testUnmodifiableList() throws Exception {
|
60 | 60 | _verifyCollection(Collections.unmodifiableList(Arrays.asList("first", "second")));
|
61 | 61 | }
|
62 | 62 |
|
| 63 | + // [databind#2265] |
| 64 | + public void testUnmodifiableListFromLinkedList() throws Exception { |
| 65 | + final List<String> input = new LinkedList<>(); |
| 66 | + input.add("first"); |
| 67 | + input.add("second"); |
| 68 | + |
| 69 | + // Can't use simple "_verifyCollection" as type may change; instead use |
| 70 | + // bit more flexible check: |
| 71 | + Collection<?> act = _writeReadCollection(Collections.unmodifiableList(input)); |
| 72 | + assertEquals(input, act); |
| 73 | + |
| 74 | + // and this check may be bit fragile (may need to revisit), but is good enough for now: |
| 75 | + assertEquals(Collections.unmodifiableList(new ArrayList<>(input)).getClass(), act.getClass()); |
| 76 | + } |
| 77 | + |
63 | 78 | public void testUnmodifiableSet() throws Exception
|
64 | 79 | {
|
65 | 80 | Set<String> input = new LinkedHashSet<>(Arrays.asList("first", "second"));
|
@@ -96,15 +111,17 @@ public void testArraysAsList() throws Exception
|
96 | 111 | /**********************************************************
|
97 | 112 | */
|
98 | 113 |
|
99 |
| - protected void _verifyCollection(Collection<?> exp) throws Exception |
100 |
| - { |
101 |
| - String json = DEFAULT_MAPPER.writeValueAsString(exp); |
102 |
| - Collection<?> act = DEFAULT_MAPPER.readValue(json, Collection.class); |
103 |
| - |
| 114 | + protected void _verifyCollection(Collection<?> exp) throws Exception { |
| 115 | + Collection<?> act = _writeReadCollection(exp); |
104 | 116 | assertEquals(exp, act);
|
105 | 117 | assertEquals(exp.getClass(), act.getClass());
|
106 | 118 | }
|
107 | 119 |
|
| 120 | + protected Collection<?> _writeReadCollection(Collection<?> input) throws Exception { |
| 121 | + final String json = DEFAULT_MAPPER.writeValueAsString(input); |
| 122 | + return DEFAULT_MAPPER.readValue(json, Collection.class); |
| 123 | + } |
| 124 | + |
108 | 125 | protected void _verifyMap(Map<?,?> exp) throws Exception
|
109 | 126 | {
|
110 | 127 | String json = DEFAULT_MAPPER.writeValueAsString(exp);
|
|
0 commit comments