use of cn.taketoday.aop.IntroductionInterceptor in project today-infrastructure by TAKETODAY.
the class DelegatingIntroductionInterceptorTests method testAutomaticInterfaceRecognitionInSubclass.
@Test
public void testAutomaticInterfaceRecognitionInSubclass() throws Exception {
final long t = 1001L;
@SuppressWarnings("serial")
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped, ITester {
@Override
public void foo() throws Exception {
}
@Override
public long getTimeStamp() {
return t;
}
}
DelegatingIntroductionInterceptor ii = new TestII();
TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target);
IntroductionAdvisor ia = new DefaultIntroductionAdvisor(ii);
assertThat(ia.isPerInstance()).isTrue();
pf.addAdvisor(0, ia);
// assertTrue(Arrays.binarySearch(pf.getProxiedInterfaces(), TimeStamped.class) != -1);
TimeStamped ts = (TimeStamped) pf.getProxy();
assertThat(ts).isInstanceOf(TimeStamped.class);
// Shouldn't proxy framework interfaces
assertThat(!(ts instanceof MethodInterceptor)).isTrue();
assertThat(!(ts instanceof IntroductionInterceptor)).isTrue();
assertThat(ts.getTimeStamp() == t).isTrue();
((ITester) ts).foo();
((ITestBean) ts).getAge();
// Test removal
ii.suppressInterface(TimeStamped.class);
// Note that we need to construct a new proxy factory,
// or suppress the interface on the proxy factory
pf = new ProxyFactory(target);
pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii));
Object o = pf.getProxy();
assertThat(!(o instanceof TimeStamped)).isTrue();
}
use of cn.taketoday.aop.IntroductionInterceptor in project today-framework by TAKETODAY.
the class DelegatingIntroductionInterceptorTests method testAutomaticInterfaceRecognitionInSubclass.
@Test
public void testAutomaticInterfaceRecognitionInSubclass() throws Exception {
final long t = 1001L;
@SuppressWarnings("serial")
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped, ITester {
@Override
public void foo() throws Exception {
}
@Override
public long getTimeStamp() {
return t;
}
}
DelegatingIntroductionInterceptor ii = new TestII();
TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target);
IntroductionAdvisor ia = new DefaultIntroductionAdvisor(ii);
assertThat(ia.isPerInstance()).isTrue();
pf.addAdvisor(0, ia);
// assertTrue(Arrays.binarySearch(pf.getProxiedInterfaces(), TimeStamped.class) != -1);
TimeStamped ts = (TimeStamped) pf.getProxy();
assertThat(ts).isInstanceOf(TimeStamped.class);
// Shouldn't proxy framework interfaces
assertThat(!(ts instanceof MethodInterceptor)).isTrue();
assertThat(!(ts instanceof IntroductionInterceptor)).isTrue();
assertThat(ts.getTimeStamp() == t).isTrue();
((ITester) ts).foo();
((ITestBean) ts).getAge();
// Test removal
ii.suppressInterface(TimeStamped.class);
// Note that we need to construct a new proxy factory,
// or suppress the interface on the proxy factory
pf = new ProxyFactory(target);
pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii));
Object o = pf.getProxy();
assertThat(!(o instanceof TimeStamped)).isTrue();
}
Aggregations