Search in sources :

Example 11 with ClassFilter

use of cn.taketoday.aop.ClassFilter 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();
}
Also used : Pointcut(cn.taketoday.aop.Pointcut) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) ClassFilter(cn.taketoday.aop.ClassFilter) MethodMatcher(cn.taketoday.aop.MethodMatcher) Test(org.junit.jupiter.api.Test)

Example 12 with ClassFilter

use of cn.taketoday.aop.ClassFilter in project today-infrastructure by TAKETODAY.

the class ClassFiltersTests method union.

@Test
void union() {
    assertThat(exceptionFilter.matches(RuntimeException.class)).isTrue();
    assertThat(exceptionFilter.matches(TestBean.class)).isFalse();
    assertThat(interfaceFilter.matches(Exception.class)).isFalse();
    assertThat(interfaceFilter.matches(TestBean.class)).isTrue();
    ClassFilter union = ClassFilters.union(exceptionFilter, interfaceFilter);
    assertThat(union.matches(RuntimeException.class)).isTrue();
    assertThat(union.matches(TestBean.class)).isTrue();
    assertThat(union.toString()).matches("^.+UnionClassFilter: \\[.+RootClassFilter: .+Exception, .+RootClassFilter: .+TestBean\\]$");
}
Also used : ClassFilter(cn.taketoday.aop.ClassFilter) Test(org.junit.jupiter.api.Test)

Aggregations

ClassFilter (cn.taketoday.aop.ClassFilter)12 Test (org.junit.jupiter.api.Test)12 MethodMatcher (cn.taketoday.aop.MethodMatcher)6 Pointcut (cn.taketoday.aop.Pointcut)6 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)6 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)6 DefaultMethodInvocation (cn.taketoday.aop.framework.DefaultMethodInvocation)2 NestedRuntimeException (cn.taketoday.core.NestedRuntimeException)2