| 
1 |  | -package base.agent.test;  | 
 | 1 | +package base.agent;  | 
2 | 2 | 
 
  | 
3 |  | -import base.agent.cglibproxy.CGlibProxyFactory;  | 
4 |  | -import base.agent.jdkproxy.JDKProxyFactory;  | 
5 |  | -import base.agent.origin.IUserDao;  | 
6 |  | -import base.agent.origin.UserDao;  | 
7 |  | -import base.agent.origin.UserDaoWithoutInterface;  | 
8 |  | -import base.agent.staticproxy.StaticUserDaoProxy;  | 
 | 3 | +import base.agent.proxy.cglib.CGlibProxyFactory;  | 
 | 4 | +import base.agent.proxy.jdk.JDKProxyFactory;  | 
 | 5 | +import base.agent.target.IUserDao;  | 
 | 6 | +import base.agent.target.UserDao;  | 
 | 7 | +import base.agent.target.UserDaoWithoutInterface;  | 
 | 8 | +import base.agent.proxy.staticagent.StaticUserDaoProxy;  | 
9 | 9 | import org.junit.Test;  | 
10 | 10 | 
 
  | 
11 | 11 | /**  | 
@@ -37,33 +37,28 @@ public void testJdkProxyFactoryWithInterface() {  | 
37 | 37 |         JDKProxyFactory jdkProxyFactory = new JDKProxyFactory(targetWithInterface);  | 
38 | 38 |         // 注意,只能返回接口而不是具体实现类,否则报错,参见testJdkProxyFactoryWithoutInterface方法  | 
39 | 39 |         IUserDao iTarget = (IUserDao) jdkProxyFactory.getProxyInstance();  | 
 | 40 | +        System.out.println("ProxyObj = " + iTarget.getClass().toString());  | 
40 | 41 |         iTarget.save();  | 
41 | 42 |     }  | 
42 | 43 | 
 
  | 
 | 44 | +    @Test  | 
 | 45 | +    public void testCGlibProxyFactoryWithoutInterface() {  | 
 | 46 | +        CGlibProxyFactory cGlibProxyFactory = new CGlibProxyFactory(targetWithoutInterface);  | 
 | 47 | +        UserDaoWithoutInterface pTarget = (UserDaoWithoutInterface) cGlibProxyFactory.getProxyInstance();  | 
 | 48 | +        System.out.println("ProxyObj = " + pTarget.getClass().toString());  | 
 | 49 | +        pTarget.save();  | 
 | 50 | +    }  | 
 | 51 | + | 
43 | 52 |     /**  | 
44 |  | -     * 测试JDK静态代理实现  | 
 | 53 | +     * 测试JDK静态代理实现无接口的对象,会报错  | 
45 | 54 |      */  | 
46 | 55 |     @Test  | 
47 | 56 |     public void testJdkProxyFactoryWithoutInterface() {  | 
48 | 57 |         //jdk动态代理  | 
49 | 58 |         JDKProxyFactory jdkProxyFactory = new JDKProxyFactory(targetWithoutInterface);  | 
50 | 59 |         // 注意,只能返回接口而不是具体实现类,否则报如下错误  | 
51 |  | -        UserDaoWithoutInterface iTarget = (UserDaoWithoutInterface) jdkProxyFactory.getProxyInstance();  | 
52 |  | -        iTarget.save();  | 
53 |  | -    }  | 
54 |  | - | 
55 |  | -    @Test  | 
56 |  | -    public void testCGlibProxyFactoryWithoutInterface(){  | 
57 |  | -        CGlibProxyFactory cGlibProxyFactory = new CGlibProxyFactory(targetWithoutInterface);  | 
58 |  | -        UserDaoWithoutInterface dao = (UserDaoWithoutInterface) cGlibProxyFactory.getProxyInstance();  | 
59 |  | -        dao.save();  | 
 | 60 | +        UserDaoWithoutInterface pTarget = (UserDaoWithoutInterface) jdkProxyFactory.getProxyInstance();  | 
 | 61 | +        System.out.println("ProxyObj = " + pTarget.getClass().toString());  | 
 | 62 | +        pTarget.save();  | 
60 | 63 |     }  | 
61 |  | - | 
62 |  | -    @Test  | 
63 |  | -    public void testCGlibProxyFactoryWithInterface(){  | 
64 |  | -        CGlibProxyFactory cGlibProxyFactory = new CGlibProxyFactory(targetWithInterface);  | 
65 |  | -        UserDao dao = (UserDao) cGlibProxyFactory.getProxyInstance();  | 
66 |  | -        dao.save();  | 
67 |  | -    }  | 
68 |  | - | 
69 | 64 | }  | 
0 commit comments