ProxyUtil { public static Class<?> getTargetClass(Object proxy) { if (proxy == null) { throw new IllegalArgumentException("Proxy object is null."); } if (AopUtils.isCglibProxy(proxy)) { return proxy.getClass().getSuperclass(); } if (proxy instanceof Advised) { do { proxy = getAdvisedTarget((Advised) proxy); } while (Proxy.isProxyClass(proxy.getClass())); } return proxy.getClass(); }  static Class<?> getTargetClass(Object proxy);  }
@Test public void testGetTargetClass01() throws Exception { try { ProxyUtil.getTargetClass(null); fail(); } catch (IllegalArgumentException e) { assertEquals("Proxy object is null.", e.getMessage()); } }
@Test public void testGetTargetClass02() throws Exception { ProxyFactory pf = new ProxyFactory(new ProxyUtil_JavaBeanStub01()); pf.setProxyTargetClass(true); Object proxy = pf.getProxy(); assertTrue(AopUtils.isCglibProxy(proxy)); Class<?> result = ProxyUtil.getTargetClass(proxy); assertSame(ProxyUtil_JavaBeanStub01.class, result); }
@Test public void testGetTargetClass03() throws Exception { Class<?> result = ProxyUtil.getTargetClass( new ProxyUtil_JavaBeanStub01()); assertSame(ProxyUtil_JavaBeanStub01.class, result); }
@Test public void testGetTargetClass04() throws Exception { ProxyFactory pf = new ProxyFactory(new ProxyUtil_JavaBeanStub01()); Object proxy = pf.getProxy(); assertTrue(AopUtils.isJdkDynamicProxy(proxy)); Class<?> result = ProxyUtil.getTargetClass(proxy); assertSame(ProxyUtil_JavaBeanStub01.class, result); }
@Test public void testGetTargetClass05() throws Exception { ProxyFactory parentPf = new ProxyFactory(new ProxyUtil_JavaBeanStub01()); Object parent = parentPf.getProxy(); ProxyFactory pf = new ProxyFactory(parent); Object proxy = pf.getProxy(); assertTrue(AopUtils.isJdkDynamicProxy(proxy)); Class<?> result = ProxyUtil.getTargetClass(proxy); assertSame(ProxyUtil_JavaBeanStub01.class, result); }