@Test
public void testRemoveAdvisorByIndex() {
TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor();
CountingBeforeAdvice cba = new CountingBeforeAdvice();
Advisor advisor = new DefaultPointcutAdvisor(cba);
pf.addAdvice(nop);
pf.addAdvisor(advisor);
NopInterceptor nop2 = new NopInterceptor();
pf.addAdvice(nop2);
ITestBean proxied = (ITestBean) pf.getProxy();
proxied.setAge(5);
assertEquals(1, cba.getCalls());
assertEquals(1, nop.getCount());
assertEquals(1, nop2.getCount());
// Removes counting before advisor
pf.removeAdvisor(1);
assertEquals(5, proxied.getAge());
assertEquals(1, cba.getCalls());
assertEquals(2, nop.getCount());
assertEquals(2, nop2.getCount());
// Removes Nop1
pf.removeAdvisor(0);
assertEquals(5, proxied.getAge());
assertEquals(1, cba.getCalls());
assertEquals(2, nop.getCount());
assertEquals(3, nop2.getCount());
// Check out of bounds
try {
pf.removeAdvisor(-1);
}
catch (AopConfigException ex) {
// Ok
}
try {
pf.removeAdvisor(2);
}
catch (AopConfigException ex) {
// Ok
}
assertEquals(5, proxied.getAge());
assertEquals(4, nop2.getCount());
}