Search in sources :

Example 11 with MethodMatcher

use of org.springframework.aop.MethodMatcher in project spring-framework by spring-projects.

the class CallCountingInterceptor method testMatchWithArgs.

@Test
public void testMatchWithArgs() throws Exception {
    String expression = "execution(void org.springframework.tests.sample.beans.TestBean.setSomeNumber(Number)) && args(Double)";
    Pointcut pointcut = getPointcut(expression);
    ClassFilter classFilter = pointcut.getClassFilter();
    MethodMatcher methodMatcher = pointcut.getMethodMatcher();
    assertMatchesTestBeanClass(classFilter);
    // not currently testable in a reliable fashion
    //assertDoesNotMatchStringClass(classFilter);
    assertTrue("Should match with setSomeNumber with Double input", methodMatcher.matches(setSomeNumber, TestBean.class, new Double(12)));
    assertFalse("Should not match setSomeNumber with Integer input", methodMatcher.matches(setSomeNumber, TestBean.class, new Integer(11)));
    assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class));
    assertTrue("Should be a runtime match", methodMatcher.isRuntime());
}
Also used : Pointcut(org.springframework.aop.Pointcut) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) ClassFilter(org.springframework.aop.ClassFilter) MethodMatcher(org.springframework.aop.MethodMatcher) Test(org.junit.Test)

Aggregations

MethodMatcher (org.springframework.aop.MethodMatcher)11 Test (org.junit.Test)8 ITestBean (org.springframework.tests.sample.beans.ITestBean)7 TestBean (org.springframework.tests.sample.beans.TestBean)7 Pointcut (org.springframework.aop.Pointcut)4 ClassFilter (org.springframework.aop.ClassFilter)3 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)1 Advisor (org.springframework.aop.Advisor)1 IntroductionAdvisor (org.springframework.aop.IntroductionAdvisor)1 IntroductionAwareMethodMatcher (org.springframework.aop.IntroductionAwareMethodMatcher)1 PointcutAdvisor (org.springframework.aop.PointcutAdvisor)1 AdvisorAdapterRegistry (org.springframework.aop.framework.adapter.AdvisorAdapterRegistry)1 GlobalAdvisorAdapterRegistry (org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry)1 ComposablePointcut (org.springframework.aop.support.ComposablePointcut)1 StaticMethodMatcher (org.springframework.aop.support.StaticMethodMatcher)1