1 46 package org.codehaus.groovy.runtime; 47 48 import java.lang.reflect.Method ; 49 50 import junit.framework.TestCase; 51 52 56 public class NewStaticMetaMethodTest extends TestCase { 57 58 public void testInvokeMetaMethod() throws Exception { 59 Method method = getClass().getMethod("dummyMethod", new Class [] { String .class, String .class }); 60 assertTrue("Should have found a method", method != null); 61 62 NewInstanceMetaMethod metaMethod = createNewMetaMethod(method); 63 64 Object answer = metaMethod.invoke("abc", new Object [] { "xyz" }); 65 assertEquals("def", answer); 66 67 assertTrue("Should not appear as static method", metaMethod.isStatic() == false); 68 } 69 70 public void testInvokeDefaultGroovyMethod() throws Exception { 71 Method method = DefaultGroovyMethods.class.getMethod("plus", new Class [] { String .class, Object .class }); 72 assertTrue("Should have found a method", method != null); 73 74 NewInstanceMetaMethod metaMethod = createNewMetaMethod(method); 75 76 Object answer = metaMethod.invoke("abc", new Object [] { "123" }); 77 assertEquals("abc123", answer); 78 79 System.out.println("Found: " + answer); 80 } 81 82 public void testInvokeDefaultGroovyMethodUsingMetaClass() { 83 Object answer = InvokerHelper.invokeMethod("abc", "plus", new Object [] { "123" }); 84 assertEquals("abc123", answer); 85 86 System.out.println("Found: " + answer); 87 } 88 89 public static String dummyMethod(String foo, String bar) throws Exception { 90 assertEquals("abc", foo); 91 assertEquals("xyz", bar); 92 return "def"; 93 } 94 95 protected NewInstanceMetaMethod createNewMetaMethod(Method method) { 96 return new NewInstanceMetaMethod(new ReflectionMetaMethod(method)); 97 } 98 } 99 | Popular Tags |