1 package org.apache.velocity.test; 2 3 18 19 import java.util.ArrayList ; 20 21 import java.lang.reflect.Method ; 22 23 import org.apache.velocity.app.Velocity; 24 25 import org.apache.velocity.runtime.RuntimeSingleton; 26 27 import junit.framework.TestCase; 28 29 37 public class IntrospectorTestCase2 extends BaseTestCase 38 { 39 40 IntrospectorTestCase2() 41 { 42 super("IntrospectorTestCase2"); 43 } 44 45 48 public IntrospectorTestCase2(String name) 49 { 50 super(name); 51 } 52 53 58 public static junit.framework.Test suite () 59 { 60 return new IntrospectorTestCase2(); 61 } 62 63 public void runTest() 64 { 65 try 66 { 67 Velocity.init(); 68 69 Method method; 70 String result; 71 Tester t = new Tester(); 72 73 Object [] params = { new Foo(), new Foo() }; 74 75 method = RuntimeSingleton.getIntrospector() 76 .getMethod( Tester.class, "find", params ); 77 78 if ( method == null) 79 fail("Returned method was null"); 80 81 result = (String ) method.invoke( t, params); 82 83 if ( !result.equals( "Bar-Bar" ) ) 84 { 85 fail("Should have gotten 'Bar-Bar' : recieved '" + result + "'"); 86 } 87 88 91 92 method = RuntimeSingleton.getIntrospector() 93 .getMethod( Tester2.class, "find", params ); 94 95 if ( method != null) 96 fail("Introspector shouldn't have found a method as it's ambiguous."); 97 } 98 catch (Exception e) 99 { 100 fail( e.toString() ); 101 } 102 } 103 104 public interface Woogie 105 { 106 } 107 108 public static class Bar implements Woogie 109 { 110 int i; 111 } 112 113 public static class Foo extends Bar 114 { 115 int j; 116 } 117 118 public static class Tester 119 { 120 public static String find(Woogie w, Object o ) 121 { 122 return "Woogie-Object"; 123 } 124 125 public static String find(Object w, Bar o ) 126 { 127 return "Object-Bar"; 128 } 129 130 public static String find(Bar w, Bar o ) 131 { 132 return "Bar-Bar"; 133 } 134 135 public static String find( Object o ) 136 { 137 return "Object"; 138 } 139 140 public static String find( Woogie o ) 141 { 142 return "Woogie"; 143 } 144 } 145 146 public static class Tester2 147 { 148 public static String find(Woogie w, Object o ) 149 { 150 return "Woogie-Object"; 151 } 152 153 public static String find(Object w, Bar o ) 154 { 155 return "Object-Bar"; 156 } 157 158 public static String find(Bar w, Object o ) 159 { 160 return "Bar-Object"; 161 } 162 163 public static String find( Object o ) 164 { 165 return "Object"; 166 } 167 168 public static String find( Woogie o ) 169 { 170 return "Woogie"; 171 } 172 } 173 } 174 | Popular Tags |