1 package org.apache.velocity.test;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.lang.reflect.Method;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28
29 import org.apache.velocity.runtime.RuntimeSingleton;
30
31
32
33
34
35
36
37 public class Introspector3TestCase extends BaseTestCase
38 {
39
40
41
42 public Introspector3TestCase(String name)
43 {
44 super(name);
45 }
46
47 public static Test suite()
48 {
49 return new TestSuite(Introspector3TestCase.class);
50 }
51
52 public void testSimple()
53 throws Exception
54 {
55 Method method;
56 String result;
57
58 MethodProvider mp = new MethodProvider();
59
60
61
62
63
64 Object[] listIntInt = { new ArrayList(), new Integer(1), new Integer(2) };
65 Object[] listLongList = { new ArrayList(), new Long(1), new ArrayList() };
66 Object[] intInt = { new Integer(1), new Integer(2) };
67 Object[] longInt = { new Long(1), new Integer(2) };
68 Object[] longLong = { new Long(1), new Long(2) };
69
70 method = RuntimeSingleton.getIntrospector().getMethod(
71 MethodProvider.class, "lii", listIntInt);
72 result = (String) method.invoke(mp, listIntInt);
73
74 assertTrue(result.equals("lii"));
75
76 method = RuntimeSingleton.getIntrospector().getMethod(
77 MethodProvider.class, "ii", intInt);
78 result = (String) method.invoke(mp, intInt);
79
80 assertTrue(result.equals("ii"));
81
82 method = RuntimeSingleton.getIntrospector().getMethod(
83 MethodProvider.class, "ll", longInt);
84 result = (String) method.invoke(mp, longInt);
85
86 assertTrue(result.equals("ll"));
87
88
89
90
91
92 method = RuntimeSingleton.getIntrospector().getMethod(
93 MethodProvider.class, "ll", longLong);
94 result = (String) method.invoke(mp, longLong);
95
96 assertTrue(result.equals("ll"));
97
98 method = RuntimeSingleton.getIntrospector().getMethod(
99 MethodProvider.class, "lll", listLongList);
100 result = (String) method.invoke(mp, listLongList);
101
102 assertTrue(result.equals("lll"));
103
104
105
106
107
108 Object [] oa = {null, new Integer(0)};
109 method = RuntimeSingleton.getIntrospector().getMethod(
110 MethodProvider.class, "lll", oa );
111 result = (String) method.invoke(mp, oa);
112
113 assertTrue(result.equals("Listl"));
114
115 }
116
117 public static class MethodProvider
118 {
119 public String ii(int p, int d)
120 {
121 return "ii";
122 }
123
124 public String lii(List s, int p, int d)
125 {
126 return "lii";
127 }
128
129 public String lll(List s, long p, List d)
130 {
131 return "lll";
132 }
133
134
135 public String lll(List s, long p, int d)
136 {
137 return "lli";
138 }
139
140 public String lll(List s, long p)
141 {
142 return "Listl";
143 }
144
145 public String ll(long p, long d)
146 {
147 return "ll";
148 }
149
150 }
151 }