@Test public void testInterceptor() { StringBuffer log = new StringBuffer(); pico.registerInterceptor( cuts.instancesOf(Dao.class), cuts.allMethods(), new LoggingInterceptor(log)); pico.addComponent(Dao.class, DaoImpl.class); Dao dao = pico.getComponent(Dao.class); verifyIntercepted(dao, log); }
@Test public void testContainerSuppliedInterceptor() { pico.registerInterceptor( cuts.instancesOf(Dao.class), cuts.allMethods(), LoggingInterceptor.class); pico.addComponent("log", StringBuffer.class); pico.addComponent(LoggingInterceptor.class); pico.addComponent(Dao.class, DaoImpl.class); Dao dao = pico.getComponent(Dao.class); StringBuffer log = (StringBuffer) pico.getComponent("log"); verifyIntercepted(dao, log); }
@Test public void testComponentInterceptor() { StringBuffer log = new StringBuffer(); pico.registerInterceptor( cuts.component("intercepted"), cuts.allMethods(), new LoggingInterceptor(log)); pico.addComponent("intercepted", DaoImpl.class); pico.addComponent("notIntercepted", DaoImpl.class); Dao intercepted = (Dao) pico.getComponent("intercepted"); Dao notIntercepted = (Dao) pico.getComponent("notIntercepted"); verifyIntercepted(intercepted, log); verifyNotIntercepted(notIntercepted, log); }
@Test public void testContainerSuppliedComponentInterceptor() { pico.registerInterceptor( cuts.component("intercepted"), cuts.allMethods(), LoggingInterceptor.class); pico.addComponent("log", StringBuffer.class); pico.addComponent(LoggingInterceptor.class); pico.addComponent("intercepted", DaoImpl.class); pico.addComponent("notIntercepted", DaoImpl.class); StringBuffer log = (StringBuffer) pico.getComponent("log"); Dao intercepted = (Dao) pico.getComponent("intercepted"); Dao notIntercepted = (Dao) pico.getComponent("notIntercepted"); verifyIntercepted(intercepted, log); verifyNotIntercepted(notIntercepted, log); }