TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor();
CountingBeforeAdvice cba1 = new CountingBeforeAdvice();
CountingBeforeAdvice cba2 = new CountingBeforeAdvice();
Advisor advisor1 = new DefaultPointcutAdvisor(cba1);
Advisor advisor2 = new DefaultPointcutAdvisor(cba2);
pf.addAdvisor(advisor1);
pf.addAdvice(nop);
ITestBean proxied = (ITestBean) pf.getProxy();
// Use the type cast feature
// Replace etc methods on advised should be same as on ProxyFactory
Advised advised = (Advised) proxied;
proxied.setAge(5);
assertEquals(1, cba1.getCalls());
assertEquals(0, cba2.getCalls());
assertEquals(1, nop.getCount());
assertFalse(advised.replaceAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()), advisor2));
assertTrue(advised.replaceAdvisor(advisor1, advisor2));
assertEquals(advisor2, pf.getAdvisors()[0]);
assertEquals(5, proxied.getAge());
assertEquals(1, cba1.getCalls());
assertEquals(2, nop.getCount());
assertEquals(1, cba2.getCalls());
assertFalse(pf.replaceAdvisor(new DefaultPointcutAdvisor(null), advisor1));
}