KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > velocity > test > IntrospectorTestCase3


1 package org.apache.velocity.test;
2
3 /*
4  * Copyright 2001,2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import java.lang.reflect.Method JavaDoc;
23
24 import org.apache.velocity.runtime.RuntimeSingleton;
25
26 import junit.framework.TestCase;
27 import junit.framework.Test;
28 import junit.framework.TestSuite;
29
30 /**
31  * Simple introspector test case for primitive problem found in 1.3
32  *
33  * @author <a HREF="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
34  * @version $Id: IntrospectorTestCase3.java,v 1.2.4.1 2004/03/03 23:23:04 geirm Exp $
35  */

36 public class IntrospectorTestCase3 extends BaseTestCase
37 {
38     /**
39       * Creates a new instance.
40       */

41     public IntrospectorTestCase3(String JavaDoc name)
42     {
43         super(name);
44     }
45
46     public static Test suite()
47     {
48         return new TestSuite(IntrospectorTestCase3.class);
49     }
50
51     public void testSimple()
52         throws Exception JavaDoc
53     {
54         Method JavaDoc method;
55         String JavaDoc result;
56         String JavaDoc type;
57
58         MethodProvider mp = new MethodProvider();
59
60         /*
61          * string integer
62          */

63
64         Object JavaDoc[] listIntInt = { new ArrayList JavaDoc(), new Integer JavaDoc(1), new Integer JavaDoc(2) };
65         Object JavaDoc[] listLongList = { new ArrayList JavaDoc(), new Long JavaDoc(1), new ArrayList JavaDoc() };
66         Object JavaDoc[] listLongInt = { new ArrayList JavaDoc(), new Long JavaDoc(1), new Integer JavaDoc(2) };
67         Object JavaDoc[] intInt = { new Integer JavaDoc(1), new Integer JavaDoc(2) };
68         Object JavaDoc[] longInt = { new Long JavaDoc(1), new Integer JavaDoc(2) };
69         Object JavaDoc[] longLong = { new Long JavaDoc(1), new Long JavaDoc(2) };
70
71         method = RuntimeSingleton.getIntrospector().getMethod(
72             MethodProvider.class, "lii", listIntInt);
73         result = (String JavaDoc) method.invoke(mp, listIntInt);
74
75         assertTrue(result.equals("lii"));
76
77         method = RuntimeSingleton.getIntrospector().getMethod(
78             MethodProvider.class, "ii", intInt);
79         result = (String JavaDoc) method.invoke(mp, intInt);
80
81         assertTrue(result.equals("ii"));
82
83         method = RuntimeSingleton.getIntrospector().getMethod(
84             MethodProvider.class, "ll", longInt);
85         result = (String JavaDoc) method.invoke(mp, longInt);
86
87         assertTrue(result.equals("ll"));
88
89         /*
90          * test overloading with primitives
91          */

92
93         method = RuntimeSingleton.getIntrospector().getMethod(
94             MethodProvider.class, "ll", longLong);
95         result = (String JavaDoc) method.invoke(mp, longLong);
96
97         assertTrue(result.equals("ll"));
98
99         method = RuntimeSingleton.getIntrospector().getMethod(
100             MethodProvider.class, "lll", listLongList);
101         result = (String JavaDoc) method.invoke(mp, listLongList);
102
103         assertTrue(result.equals("lll"));
104
105         /*
106          * test invocation with nulls
107          */

108
109         Object JavaDoc [] oa = {null, new Integer JavaDoc(0)};
110         method = RuntimeSingleton.getIntrospector().getMethod(
111             MethodProvider.class, "lll", oa );
112         result = (String JavaDoc) method.invoke(mp, oa);
113
114         assertTrue(result.equals("Listl"));
115
116     }
117
118     public static class MethodProvider
119     {
120         public String JavaDoc ii(int p, int d)
121         {
122             return "ii";
123         }
124
125         public String JavaDoc lii(List JavaDoc s, int p, int d)
126         {
127             return "lii";
128         }
129
130         public String JavaDoc lll(List JavaDoc s, long p, List JavaDoc d)
131         {
132             return "lll";
133         }
134
135
136         public String JavaDoc lll(List JavaDoc s, long p, int d)
137         {
138             return "lli";
139         }
140
141         public String JavaDoc lll(List JavaDoc s, long p)
142         {
143             return "Listl";
144         }
145
146         public String JavaDoc ll(long p, long d)
147         {
148             return "ll";
149         }
150
151     }
152 }
153
Popular Tags