AopTargetUtils { public static Object getTarget(final Object proxy) { if (!AopUtils.isAopProxy(proxy)) { return proxy; } if (AopUtils.isJdkDynamicProxy(proxy)) { return getProxyTargetObject(proxy, "h"); } else { return getProxyTargetObject(proxy, "CGLIB$CALLBACK_0"); } }  static Object getTarget(final Object proxy);  }
@Test public void assertJdkDynamicProxyForGetTarget() { ElasticJob target = new TargetJob(); ProxyFactory pf = new ProxyFactory(target); pf.addInterface(ElasticJob.class); ElasticJob proxy = (ElasticJob) pf.getProxy(); assertTrue(AopUtils.isJdkDynamicProxy(proxy)); assertThat(AopTargetUtils.getTarget(proxy), is(target)); }
@Test public void assertCglibProxyForGetTarget() { ElasticJob target = new TargetJob(); ProxyFactory pf = new ProxyFactory(target); pf.setProxyTargetClass(true); ElasticJob proxy = (ElasticJob) pf.getProxy(); assertTrue(AopUtils.isCglibProxy(proxy)); assertThat(AopTargetUtils.getTarget(proxy), is(target)); }
@Test public void assertNoneProxyForGetTarget() { ElasticJob proxy = new TargetJob(); assertFalse(AopUtils.isAopProxy(proxy)); assertThat(AopTargetUtils.getTarget(proxy), is(proxy)); }