|
| 1 | +package com.fasterxml.jackson.failing; |
| 2 | + |
| 3 | +import java.util.*; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.databind.BaseMapTest; |
| 6 | +import com.fasterxml.jackson.databind.JavaType; |
| 7 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 8 | +import com.fasterxml.jackson.databind.type.CollectionType; |
| 9 | +import com.fasterxml.jackson.databind.type.MapType; |
| 10 | + |
| 11 | +// for [databind#1415] |
| 12 | +public class CollectionType1415Test extends BaseMapTest |
| 13 | +{ |
| 14 | + static abstract class LongList implements List<Long> { } |
| 15 | + |
| 16 | + static abstract class StringLongMap implements Map<String,Long> { } |
| 17 | + |
| 18 | + /* |
| 19 | + /********************************************************** |
| 20 | + /* Unit tests |
| 21 | + /********************************************************** |
| 22 | + */ |
| 23 | + |
| 24 | + private final ObjectMapper MAPPER = new ObjectMapper(); |
| 25 | + |
| 26 | + public void testExplicitCollectionType() throws Exception |
| 27 | + { |
| 28 | + JavaType t = MAPPER.getTypeFactory() |
| 29 | + .constructCollectionType(LongList.class, Long.class); |
| 30 | + assertEquals(LongList.class, t.getRawClass()); |
| 31 | + assertEquals(Long.class, t.getContentType().getRawClass()); |
| 32 | + } |
| 33 | + |
| 34 | + public void testImplicitCollectionType() throws Exception |
| 35 | + { |
| 36 | + JavaType t = MAPPER.getTypeFactory() |
| 37 | + .constructParametricType(List.class, Long.class); |
| 38 | + assertEquals(CollectionType.class, t.getClass()); |
| 39 | + assertEquals(List.class, t.getRawClass()); |
| 40 | + assertEquals(Long.class, t.getContentType().getRawClass()); |
| 41 | + } |
| 42 | + |
| 43 | + public void testExplicitMapType() throws Exception |
| 44 | + { |
| 45 | + JavaType t = MAPPER.getTypeFactory() |
| 46 | + .constructMapType(StringLongMap.class, |
| 47 | + String.class, Long.class); |
| 48 | + assertEquals(StringLongMap.class, t.getRawClass()); |
| 49 | + assertEquals(String.class, t.getKeyType().getRawClass()); |
| 50 | + assertEquals(Long.class, t.getContentType().getRawClass()); |
| 51 | + } |
| 52 | + |
| 53 | + public void testImplicitMapType() throws Exception |
| 54 | + { |
| 55 | + JavaType t = MAPPER.getTypeFactory() |
| 56 | + .constructParametricType(Map.class, Long.class, Boolean.class); |
| 57 | + assertEquals(MapType.class, t.getClass()); |
| 58 | + assertEquals(Long.class, t.getKeyType().getRawClass()); |
| 59 | + assertEquals(Boolean.class, t.getContentType().getRawClass()); |
| 60 | + } |
| 61 | +} |
0 commit comments