1 16 package net.sf.cglib.proxy; 17 18 import java.lang.reflect.*; 19 import junit.framework.*; 20 import net.sf.cglib.CodeGenTestCase; 21 22 public class TestInterfaceMaker extends CodeGenTestCase 23 { 24 public void testStandalone() throws Exception { 25 InterfaceMaker im = new InterfaceMaker(); 26 im.add(D1.class); 27 im.add(D2.class); 28 Class iface = im.create(); 29 Method[] methods = iface.getMethods(); 30 assertTrue(methods.length == 2); 31 String name1 = methods[0].getName(); 32 String name2 = methods[1].getName(); 33 assertTrue(("herby".equals(name1) && "derby".equals(name2)) || 34 ("herby".equals(name2) && "derby".equals(name1))); 35 } 36 37 public void testEnhancer() throws Exception { 38 InterfaceMaker im = new InterfaceMaker(); 39 im.add(D1.class); 40 im.add(D2.class); 41 Class iface = im.create(); 42 Object obj = Enhancer.create(Object .class, new Class []{ iface }, new MethodInterceptor() { 43 public Object intercept(Object obj, Method method, Object [] args, MethodProxy proxy) { 44 return "test"; 45 } 46 }); 47 Method method = obj.getClass().getMethod("herby", null); 48 assertTrue("test".equals(method.invoke(obj, null))); 49 } 50 51 public TestInterfaceMaker(String testName) { 52 super(testName); 53 } 54 55 public static Test suite() { 56 return new TestSuite(TestInterfaceMaker.class); 57 } 58 59 public static void main(String args[]) { 60 String [] testCaseName = {TestInterfaceMaker.class.getName()}; 61 junit.textui.TestRunner.main(testCaseName); 62 } 63 64 public void perform(ClassLoader loader) throws Throwable { 65 } 66 67 public void testFailOnMemoryLeak() throws Throwable { 68 } 69 70 } 71 | Popular Tags |