1 package org.apache.velocity.test; 2 3 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import java.lang.reflect.Method ; 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 36 public class IntrospectorTestCase3 extends BaseTestCase 37 { 38 41 public IntrospectorTestCase3(String 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 53 { 54 Method method; 55 String result; 56 String type; 57 58 MethodProvider mp = new MethodProvider(); 59 60 63 64 Object [] listIntInt = { new ArrayList (), new Integer (1), new Integer (2) }; 65 Object [] listLongList = { new ArrayList (), new Long (1), new ArrayList () }; 66 Object [] listLongInt = { new ArrayList (), new Long (1), new Integer (2) }; 67 Object [] intInt = { new Integer (1), new Integer (2) }; 68 Object [] longInt = { new Long (1), new Integer (2) }; 69 Object [] longLong = { new Long (1), new Long (2) }; 70 71 method = RuntimeSingleton.getIntrospector().getMethod( 72 MethodProvider.class, "lii", listIntInt); 73 result = (String ) method.invoke(mp, listIntInt); 74 75 assertTrue(result.equals("lii")); 76 77 method = RuntimeSingleton.getIntrospector().getMethod( 78 MethodProvider.class, "ii", intInt); 79 result = (String ) method.invoke(mp, intInt); 80 81 assertTrue(result.equals("ii")); 82 83 method = RuntimeSingleton.getIntrospector().getMethod( 84 MethodProvider.class, "ll", longInt); 85 result = (String ) method.invoke(mp, longInt); 86 87 assertTrue(result.equals("ll")); 88 89 92 93 method = RuntimeSingleton.getIntrospector().getMethod( 94 MethodProvider.class, "ll", longLong); 95 result = (String ) method.invoke(mp, longLong); 96 97 assertTrue(result.equals("ll")); 98 99 method = RuntimeSingleton.getIntrospector().getMethod( 100 MethodProvider.class, "lll", listLongList); 101 result = (String ) method.invoke(mp, listLongList); 102 103 assertTrue(result.equals("lll")); 104 105 108 109 Object [] oa = {null, new Integer (0)}; 110 method = RuntimeSingleton.getIntrospector().getMethod( 111 MethodProvider.class, "lll", oa ); 112 result = (String ) method.invoke(mp, oa); 113 114 assertTrue(result.equals("Listl")); 115 116 } 117 118 public static class MethodProvider 119 { 120 public String ii(int p, int d) 121 { 122 return "ii"; 123 } 124 125 public String lii(List s, int p, int d) 126 { 127 return "lii"; 128 } 129 130 public String lll(List s, long p, List d) 131 { 132 return "lll"; 133 } 134 135 136 public String lll(List s, long p, int d) 137 { 138 return "lli"; 139 } 140 141 public String lll(List s, long p) 142 { 143 return "Listl"; 144 } 145 146 public String ll(long p, long d) 147 { 148 return "ll"; 149 } 150 151 } 152 } 153 | Popular Tags |