|
36 | 36 | import org.junit.Ignore;
|
37 | 37 | import org.junit.Test;
|
38 | 38 | import org.springframework.core.MethodParameter;
|
39 |
| -import org.springframework.core.convert.support.DefaultConversionService; |
40 | 39 |
|
41 | 40 | /**
|
42 | 41 | * @author Keith Donald
|
@@ -653,6 +652,74 @@ public void mapNested() {
|
653 | 652 | assertEquals(Integer.class, desc.getMapValueType().getMapValueType().getType());
|
654 | 653 | }
|
655 | 654 |
|
| 655 | + @Test |
| 656 | + public void narrow() { |
| 657 | + TypeDescriptor desc = TypeDescriptor.valueOf(Number.class); |
| 658 | + Integer value = new Integer(3); |
| 659 | + desc = desc.narrow(value); |
| 660 | + assertEquals(Integer.class, desc.getType()); |
| 661 | + } |
| 662 | + |
| 663 | + @Test |
| 664 | + public void elementType() { |
| 665 | + TypeDescriptor desc = TypeDescriptor.valueOf(List.class); |
| 666 | + Integer value = new Integer(3); |
| 667 | + desc = desc.elementType(value); |
| 668 | + assertEquals(Integer.class, desc.getType()); |
| 669 | + } |
| 670 | + |
| 671 | + @Test |
| 672 | + public void elementTypePreserveContext() throws Exception { |
| 673 | + TypeDescriptor desc = new TypeDescriptor(getClass().getField("listPreserveContext")); |
| 674 | + assertEquals(Integer.class, desc.getElementType().getElementType().getType()); |
| 675 | + List<Integer> value = new ArrayList<Integer>(3); |
| 676 | + desc = desc.elementType(value); |
| 677 | + assertEquals(Integer.class, desc.getElementType().getType()); |
| 678 | + assertNotNull(desc.getAnnotation(FieldAnnotation.class)); |
| 679 | + } |
| 680 | + |
| 681 | + @FieldAnnotation |
| 682 | + public List<List<Integer>> listPreserveContext; |
| 683 | + |
| 684 | + @Test |
| 685 | + public void mapKeyType() { |
| 686 | + TypeDescriptor desc = TypeDescriptor.valueOf(Map.class); |
| 687 | + Integer value = new Integer(3); |
| 688 | + desc = desc.mapKeyType(value); |
| 689 | + assertEquals(Integer.class, desc.getType()); |
| 690 | + } |
| 691 | + |
| 692 | + @Test |
| 693 | + public void mapKeyTypePreserveContext() throws Exception { |
| 694 | + TypeDescriptor desc = new TypeDescriptor(getClass().getField("mapPreserveContext")); |
| 695 | + assertEquals(Integer.class, desc.getMapKeyType().getElementType().getType()); |
| 696 | + List<Integer> value = new ArrayList<Integer>(3); |
| 697 | + desc = desc.mapKeyType(value); |
| 698 | + assertEquals(Integer.class, desc.getElementType().getType()); |
| 699 | + assertNotNull(desc.getAnnotation(FieldAnnotation.class)); |
| 700 | + } |
| 701 | + |
| 702 | + @FieldAnnotation |
| 703 | + public Map<List<Integer>, List<Integer>> mapPreserveContext; |
| 704 | + |
| 705 | + @Test |
| 706 | + public void mapValueType() { |
| 707 | + TypeDescriptor desc = TypeDescriptor.valueOf(Map.class); |
| 708 | + Integer value = new Integer(3); |
| 709 | + desc = desc.mapValueType(value); |
| 710 | + assertEquals(Integer.class, desc.getType()); |
| 711 | + } |
| 712 | + |
| 713 | + @Test |
| 714 | + public void mapValueTypePreserveContext() throws Exception { |
| 715 | + TypeDescriptor desc = new TypeDescriptor(getClass().getField("mapPreserveContext")); |
| 716 | + assertEquals(Integer.class, desc.getMapValueType().getElementType().getType()); |
| 717 | + List<Integer> value = new ArrayList<Integer>(3); |
| 718 | + desc = desc.mapValueType(value); |
| 719 | + assertEquals(Integer.class, desc.getElementType().getType()); |
| 720 | + assertNotNull(desc.getAnnotation(FieldAnnotation.class)); |
| 721 | + } |
| 722 | + |
656 | 723 | @Test
|
657 | 724 | public void equals() throws Exception {
|
658 | 725 | TypeDescriptor t1 = TypeDescriptor.valueOf(String.class);
|
|
0 commit comments