/** * Match all methods that <b>both</b> the given pointcuts match. * @param pc1 the first Pointcut * @param pc2 the second Pointcut * @return a distinct Pointcut that matches all methods that both * of the given Pointcuts match */ public static Pointcut intersection(Pointcut pc1, Pointcut pc2) { return new ComposablePointcut(pc1).intersection(pc2); }
@Test public void testEqualsAndHashCode() throws Exception { ComposablePointcut pc1 = new ComposablePointcut(); ComposablePointcut pc2 = new ComposablePointcut(); assertEquals(pc1, pc2); assertEquals(pc1.hashCode(), pc2.hashCode()); pc1.intersection(GETTER_METHOD_MATCHER); assertFalse(pc1.equals(pc2)); assertFalse(pc1.hashCode() == pc2.hashCode()); pc2.intersection(GETTER_METHOD_MATCHER); assertEquals(pc1, pc2); assertEquals(pc1.hashCode(), pc2.hashCode()); pc1.union(GET_AGE_METHOD_MATCHER); pc2.union(GET_AGE_METHOD_MATCHER); assertEquals(pc1, pc2); assertEquals(pc1.hashCode(), pc2.hashCode()); }
@Test public void testIntersectionMethodMatcher() { ComposablePointcut pc = new ComposablePointcut(); assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); pc.intersection(GETTER_METHOD_MATCHER); assertFalse(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); pc.intersection(GET_AGE_METHOD_MATCHER); // Use the Pointcuts matches method assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); }
@Test public void testFilterByClass() throws NoSuchMethodException { ComposablePointcut pc = new ComposablePointcut(); assertTrue(pc.getClassFilter().matches(Object.class)); ClassFilter cf = new RootClassFilter(Exception.class); pc.intersection(cf); assertFalse(pc.getClassFilter().matches(Object.class)); assertTrue(pc.getClassFilter().matches(Exception.class)); pc.intersection(new RootClassFilter(NestedRuntimeException.class)); assertFalse(pc.getClassFilter().matches(Exception.class)); assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class)); assertFalse(pc.getClassFilter().matches(String.class)); pc.union(new RootClassFilter(String.class)); assertFalse(pc.getClassFilter().matches(Exception.class)); assertTrue(pc.getClassFilter().matches(String.class)); assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class)); }
/** * Match all methods that <b>both</b> the given pointcuts match. * @param pc1 the first Pointcut * @param pc2 the second Pointcut * @return a distinct Pointcut that matches all methods that both * of the given Pointcuts match */ public static Pointcut intersection(Pointcut pc1, Pointcut pc2) { return new ComposablePointcut(pc1).intersection(pc2); }
/** * Match all methods that <b>both</b> the given pointcuts match. * @param pc1 the first Pointcut * @param pc2 the second Pointcut * @return a distinct Pointcut that matches all methods that both * of the given Pointcuts match */ public static Pointcut intersection(Pointcut pc1, Pointcut pc2) { return new ComposablePointcut(pc1).intersection(pc2); }
public Pointcut getIntersectionPointcut() { ComposablePointcut cp = new ComposablePointcut(); Pointcut pt1 = new ControlFlowPointcut(WaiterDelegate.class, "service"); NameMatchMethodPointcut pt2 = new NameMatchMethodPointcut(); pt2.addMethodName("greetTo"); return cp.intersection(pt1).intersection((Pointcut) pt2); } }
/** * Match all methods that <b>both</b> the given pointcuts match * @param a input pointcut * @param b input pointput * @return a distinct Pointcut that matches all methods that both the * given pointcuts match */ public static Pointcut intersection(Pointcut a, Pointcut b) { return new ComposablePointcut(a.getClassFilter(), a.getMethodMatcher()).intersection(b); }