/** * The intersection of these two pointcuts leaves nothing. */ @Test public void testSimpleIntersection() { Pointcut intersection = Pointcuts.intersection(allClassGetterPointcut, allClassSetterPointcut); assertFalse(Pointcuts.matches(intersection, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))); assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)); assertFalse(Pointcuts.matches(intersection, TEST_BEAN_ABSQUATULATE, TestBean.class)); }
/** * Check that we can use a cflow pointcut only in conjunction with * a static pointcut: e.g. all setter methods that are invoked under * a particular class. This greatly reduces the number of calls * to the cflow pointcut, meaning that it's not so prohibitively * expensive. */ @Test public void testSelectiveApplication() { TestBean target = new TestBean(); target.setAge(27); NopInterceptor nop = new NopInterceptor(); ControlFlowPointcut cflow = new ControlFlowPointcut(One.class); Pointcut settersUnderOne = Pointcuts.intersection(Pointcuts.SETTERS, cflow); ProxyFactory pf = new ProxyFactory(target); ITestBean proxied = (ITestBean) pf.getProxy(); pf.addAdvisor(new DefaultPointcutAdvisor(settersUnderOne, nop)); // Not advised, not under One target.setAge(16); assertEquals(0, nop.getCount()); // Not advised; under One but not a setter assertEquals(16, new One().getAge(proxied)); assertEquals(0, nop.getCount()); // Won't be advised new One().set(proxied); assertEquals(1, nop.getCount()); // We saved most evaluations assertEquals(1, cflow.getEvaluations()); }
assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, MyTestBean.class)); Pointcut intersection = Pointcuts.intersection(allClassGetAgePointcut, myTestBeanGetterPointcut); assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class)); assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)); intersection = Pointcuts.intersection(intersection, myTestBeanSubclassGetterPointcut); assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class)); assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class));