1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.rblasch.convert;
17
18 import junit.framework.TestCase;
19 import org.rblasch.convert.converters.primitives.StringToIntegerConverter;
20 import org.rblasch.convert.type.Types;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 /***
26 * @author Ronald Blaschke
27 */
28 public class PConverterTest extends TestCase {
29 public void testList() throws Exception {
30 final SptConverter ci = SptConverter.createDefault();
31 final List
32 iList.add(new Integer(42));
33
34 final List
35 sList.add("42");
36
37 final Object l = ci.convert(iList, Types.findPTypeByType(Types.findTypeByClass(List.class), Types.findTypeByClass(Integer.class)), Types.findPTypeByType(Types.findTypeByClass(List.class), Types.findTypeByClass(String.class)));
38 assertEquals(sList, l);
39 }
40
41 public void testParameterized() throws Exception {
42 final SptConverter ci = SptConverter.createDefault();
43
44 final Integer[] array = new Integer[1];
45 array[0] = new Integer(42);
46
47 final Object l = ci.convert(array, Types.findPTypeByType(Types.findTypeByClass(List.class), Types.findTypeByClass(String.class)));
48 assertTrue(l instanceof List);
49 assertEquals("42", ((List) l).get(0));
50 }
51
52 public void testStringListToInteger() throws Exception {
53 final SptConverter ci = SptConverter.createDefault();
54 ci.addConverter(new StringToIntegerConverter());
55 final List
56 sList.add("42");
57
58 final List
59 iList.add(new Integer(42));
60
61 final Object l = ci.convert(sList, Types.findPTypeByType(Types.findTypeByClass(List.class), Types.findTypeByClass(String.class)), Types.findPTypeByType(Types.findTypeByClass(List.class), Types.findTypeByClass(Integer.class)));
62 assertEquals(iList, l);
63 }
64 }