use of cn.taketoday.aop.MethodMatcher in project today-infrastructure by TAKETODAY.
the class CallCountingInterceptor method testMatchExplicit.
@Test
public void testMatchExplicit() {
String expression = "execution(int cn.taketoday.beans.testfixture.beans.TestBean.getAge())";
Pointcut pointcut = getPointcut(expression);
ClassFilter classFilter = pointcut.getClassFilter();
MethodMatcher methodMatcher = pointcut.getMethodMatcher();
assertMatchesTestBeanClass(classFilter);
// not currently testable in a reliable fashion
// assertDoesNotMatchStringClass(classFilter);
assertThat(methodMatcher.isRuntime()).as("Should not be a runtime match").isFalse();
assertMatchesGetAge(methodMatcher);
assertThat(methodMatcher.matches(setAge, TestBean.class)).as("Expression should match setAge() method").isFalse();
}
use of cn.taketoday.aop.MethodMatcher in project today-infrastructure by TAKETODAY.
the class Pointcuts method matches.
/**
* Perform the least expensive check for a pointcut match.
*
* @param pointcut the pointcut to match
* @param invocation runtime invocation contains the candidate method
* and target class, arguments to the method
* @return whether there's a runtime match
*/
public static boolean matches(Pointcut pointcut, MethodInvocation invocation) {
Assert.notNull(pointcut, "Pointcut must not be null");
if (pointcut == Pointcut.TRUE) {
return true;
}
final Class<?> targetClass = AopUtils.getTargetClass(invocation);
if (pointcut.getClassFilter().matches(targetClass)) {
// Only check if it gets past first hurdle.
MethodMatcher mm = pointcut.getMethodMatcher();
if (mm.matches(invocation.getMethod(), targetClass)) {
// We may need additional runtime (argument) check.
return (!mm.isRuntime() || mm.matches(invocation));
}
}
return false;
}
use of cn.taketoday.aop.MethodMatcher in project today-infrastructure by TAKETODAY.
the class MethodMatchersTests method testDefaultMatchesAll.
@Test
public void testDefaultMatchesAll() throws Exception {
MethodMatcher defaultMm = MethodMatcher.TRUE;
assertThat(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)).isTrue();
assertThat(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)).isTrue();
}
Aggregations