Skip to content

Commit 76283ed

Browse files
author
Keith Donald
committed
narrow and elementType/keyValueType tests
1 parent a40f658 commit 76283ed

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

org.springframework.core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.junit.Ignore;
3737
import org.junit.Test;
3838
import org.springframework.core.MethodParameter;
39-
import org.springframework.core.convert.support.DefaultConversionService;
4039

4140
/**
4241
* @author Keith Donald
@@ -653,6 +652,74 @@ public void mapNested() {
653652
assertEquals(Integer.class, desc.getMapValueType().getMapValueType().getType());
654653
}
655654

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+
656723
@Test
657724
public void equals() throws Exception {
658725
TypeDescriptor t1 = TypeDescriptor.valueOf(String.class);

0 commit comments

Comments
 (0)