Search in sources :

Example 6 with ClassFilter

use of org.springframework.aop.ClassFilter 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

Test (org.junit.Test)6 ClassFilter (org.springframework.aop.ClassFilter)6 ITestBean (org.springframework.tests.sample.beans.ITestBean)5 TestBean (org.springframework.tests.sample.beans.TestBean)5 MethodMatcher (org.springframework.aop.MethodMatcher)3 Pointcut (org.springframework.aop.Pointcut)3 NestedRuntimeException (org.springframework.core.NestedRuntimeException)3