public void testVarArgsMatching() throws Exception { PointcutExpression ex = parser.parsePointcutExpression("execution(* *(String...))"); Method usesVarArgs = D.class.getMethod("varArgs", String[].class); Method noVarArgs = D.class.getMethod("nonVarArgs", String[].class); ShadowMatch sm1 = ex.matchesMethodExecution(usesVarArgs); assertTrue("should match", sm1.alwaysMatches()); ShadowMatch sm2 = ex.matchesMethodExecution(noVarArgs); assertFalse("should not match", sm2.alwaysMatches()); }
public void testReferencePointcutNoParams() { PointcutExpression pc = parser.parsePointcutExpression("foo()", C.class, new PointcutParameter[0]); ShadowMatch sMatch1 = pc.matchesMethodCall(a, b); ShadowMatch sMatch2 = pc.matchesMethodExecution(a); assertTrue("no match on call", sMatch1.neverMatches()); assertTrue("match on execution", sMatch2.alwaysMatches()); pc = parser.parsePointcutExpression( "org.aspectj.weaver.tools.Java15PointcutExpressionTest.C.foo()"); sMatch1 = pc.matchesMethodCall(a, b); sMatch2 = pc.matchesMethodExecution(a); assertTrue("no match on call", sMatch1.neverMatches()); assertTrue("match on execution", sMatch2.alwaysMatches()); }
public void testExecutionWithClassFileRetentionAnnotation() { PointcutExpression pc1 = parser.parsePointcutExpression( "execution(@org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyAnnotation * *(..))"); PointcutExpression pc2 = parser.parsePointcutExpression( "execution(@org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyClassFileRetentionAnnotation * *(..))"); ShadowMatch sMatch = pc1.matchesMethodExecution(a); assertTrue("matches", sMatch.alwaysMatches()); sMatch = pc2.matchesMethodExecution(a); assertTrue("no match", sMatch.neverMatches()); sMatch = pc1.matchesMethodExecution(b); assertTrue("no match", sMatch.neverMatches()); sMatch = pc2.matchesMethodExecution(b); assertTrue("matches", sMatch.alwaysMatches()); }
public void testGenericMethodSignatures() throws Exception { PointcutExpression ex = parser.parsePointcutExpression( "execution(* set*(java.util.List<org.aspectj.weaver.tools.Java15PointcutExpressionTest.C>))"); Method m = TestBean.class.getMethod("setFriends", List.class); ShadowMatch sm = ex.matchesMethodExecution(m); assertTrue("should match", sm.alwaysMatches()); }
public void testAtAnnotation() { PointcutExpression atAnnotation = parser.parsePointcutExpression( "@annotation(org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyAnnotation)"); ShadowMatch sMatch1 = atAnnotation.matchesMethodCall(b, a); ShadowMatch sMatch2 = atAnnotation.matchesMethodCall(a, a); assertTrue("does not match call to b", sMatch1.neverMatches()); assertTrue("matches call to a", sMatch2.alwaysMatches()); }
public void testAtWithinCode() { PointcutExpression atWithinCode = parser.parsePointcutExpression( "@withincode(org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyAnnotation)"); ShadowMatch sMatch1 = atWithinCode.matchesMethodCall(a, b); ShadowMatch sMatch2 = atWithinCode.matchesMethodCall(a, a); assertTrue("does not match from b", sMatch1.neverMatches()); assertTrue("matches from a", sMatch2.alwaysMatches()); }
public void testAtWithin() { PointcutExpression atWithin = parser.parsePointcutExpression( "@within(org.aspectj.weaver.tools.Java15PointcutExpressionTest.MyAnnotation)"); ShadowMatch sMatch1 = atWithin.matchesMethodExecution(a); ShadowMatch sMatch2 = atWithin.matchesMethodExecution(b); assertTrue("does not match a", sMatch1.neverMatches()); assertTrue("matches b", sMatch2.alwaysMatches()); }
public void testReferencePCsInOtherType() throws Exception { PointcutExpression ex = parser.parsePointcutExpression( "org.aspectj.weaver.tools.Java15PointcutExpressionTest.ExternalReferrer.d()", ExternalReferrer.class, new PointcutParameter[0]); ShadowMatch sm = ex.matchesMethodExecution(a); assertTrue("should match", sm.alwaysMatches()); sm = ex.matchesMethodExecution(b); assertTrue("does not match", sm.neverMatches()); }
public void testAtWithinCodeWithBinding() { PointcutParameter p1 = parser.createPointcutParameter("x", MyAnnotation.class); PointcutExpression atWithinCode = parser.parsePointcutExpression("@withincode(x)", A.class, new PointcutParameter[] {p1}); ShadowMatch sMatch2 = atWithinCode.matchesMethodCall(a, a); assertTrue("matches from a", sMatch2.alwaysMatches()); JoinPointMatch jpm = sMatch2.matchesJoinPoint(new A(), new A(), new Object[0]); assertEquals(1, jpm.getParameterBindings().length); MyAnnotation annOna = a.getAnnotation(MyAnnotation.class); assertEquals("MyAnnotation on a", annOna, jpm.getParameterBindings()[0].getBinding()); }
public void testAtWithinWithBinding() { PointcutParameter p1 = parser.createPointcutParameter("x", MyAnnotation.class); PointcutExpression atWithin = parser.parsePointcutExpression("@within(x)", B.class, new PointcutParameter[] {p1}); ShadowMatch sMatch1 = atWithin.matchesMethodExecution(a); ShadowMatch sMatch2 = atWithin.matchesMethodExecution(b); assertTrue("does not match a", sMatch1.neverMatches()); assertTrue("matches b", sMatch2.alwaysMatches()); JoinPointMatch jpm = sMatch2.matchesJoinPoint(new B(), new B(), new Object[0]); assertTrue(jpm.matches()); assertEquals(1, jpm.getParameterBindings().length); MyAnnotation bAnnotation = B.class.getAnnotation(MyAnnotation.class); assertEquals("annotation on B", bAnnotation, jpm.getParameterBindings()[0].getBinding()); }
public void testJavaLangMatching() throws Exception { PointcutExpression ex = parser.parsePointcutExpression("@within(java.lang.Deprecated)"); Method foo = GoldenOldie.class.getMethod("foo"); ShadowMatch sm1 = ex.matchesMethodExecution(foo); assertTrue("should match", sm1.alwaysMatches()); }