001: package org.apache.velocity.test;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.lang.reflect.Method;
023: import java.util.ArrayList;
024: import java.util.List;
025:
026: import junit.framework.Test;
027: import junit.framework.TestSuite;
028:
029: import org.apache.velocity.runtime.RuntimeSingleton;
030:
031: /**
032: * Simple introspector test case for primitive problem found in 1.3
033: *
034: * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
035: * @version $Id: Introspector3TestCase.java 463298 2006-10-12 16:10:32Z henning $
036: */
037: public class Introspector3TestCase extends BaseTestCase {
038: /**
039: * Creates a new instance.
040: */
041: public Introspector3TestCase(String name) {
042: super (name);
043: }
044:
045: public static Test suite() {
046: return new TestSuite(Introspector3TestCase.class);
047: }
048:
049: public void testSimple() throws Exception {
050: Method method;
051: String result;
052:
053: MethodProvider mp = new MethodProvider();
054:
055: /*
056: * string integer
057: */
058:
059: Object[] listIntInt = { new ArrayList(), new Integer(1),
060: new Integer(2) };
061: Object[] listLongList = { new ArrayList(), new Long(1),
062: new ArrayList() };
063: Object[] intInt = { new Integer(1), new Integer(2) };
064: Object[] longInt = { new Long(1), new Integer(2) };
065: Object[] longLong = { new Long(1), new Long(2) };
066:
067: method = RuntimeSingleton.getIntrospector().getMethod(
068: MethodProvider.class, "lii", listIntInt);
069: result = (String) method.invoke(mp, listIntInt);
070:
071: assertTrue(result.equals("lii"));
072:
073: method = RuntimeSingleton.getIntrospector().getMethod(
074: MethodProvider.class, "ii", intInt);
075: result = (String) method.invoke(mp, intInt);
076:
077: assertTrue(result.equals("ii"));
078:
079: method = RuntimeSingleton.getIntrospector().getMethod(
080: MethodProvider.class, "ll", longInt);
081: result = (String) method.invoke(mp, longInt);
082:
083: assertTrue(result.equals("ll"));
084:
085: /*
086: * test overloading with primitives
087: */
088:
089: method = RuntimeSingleton.getIntrospector().getMethod(
090: MethodProvider.class, "ll", longLong);
091: result = (String) method.invoke(mp, longLong);
092:
093: assertTrue(result.equals("ll"));
094:
095: method = RuntimeSingleton.getIntrospector().getMethod(
096: MethodProvider.class, "lll", listLongList);
097: result = (String) method.invoke(mp, listLongList);
098:
099: assertTrue(result.equals("lll"));
100:
101: /*
102: * test invocation with nulls
103: */
104:
105: Object[] oa = { null, new Integer(0) };
106: method = RuntimeSingleton.getIntrospector().getMethod(
107: MethodProvider.class, "lll", oa);
108: result = (String) method.invoke(mp, oa);
109:
110: assertTrue(result.equals("Listl"));
111:
112: }
113:
114: public static class MethodProvider {
115: public String ii(int p, int d) {
116: return "ii";
117: }
118:
119: public String lii(List s, int p, int d) {
120: return "lii";
121: }
122:
123: public String lll(List s, long p, List d) {
124: return "lll";
125: }
126:
127: public String lll(List s, long p, int d) {
128: return "lli";
129: }
130:
131: public String lll(List s, long p) {
132: return "Listl";
133: }
134:
135: public String ll(long p, long d) {
136: return "ll";
137: }
138:
139: }
140: }
|