use of cn.taketoday.aop.ClassFilter in project today-framework 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.ClassFilter in project today-framework by TAKETODAY.
the class CallCountingInterceptor method testMatchWithArgs.
@Test
public void testMatchWithArgs() throws Exception {
String expression = "execution(void cn.taketoday.beans.testfixture.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);
DefaultMethodInvocation invocation = new DefaultMethodInvocation(null, new TestBean(), setSomeNumber, TestBean.class, new Object[] { 12D }, null);
DefaultMethodInvocation invocation1 = new DefaultMethodInvocation(null, new TestBean(), setSomeNumber, TestBean.class, new Object[] { 11 }, null);
assertThat(methodMatcher.matches(invocation)).as("Should match with setSomeNumber with Double input").isTrue();
assertThat(methodMatcher.matches(invocation1)).as("Should not match setSomeNumber with Integer input").isFalse();
assertThat(methodMatcher.matches(getAge, TestBean.class)).as("Should not match getAge").isFalse();
assertThat(methodMatcher.isRuntime()).as("Should be a runtime match").isTrue();
}
use of cn.taketoday.aop.ClassFilter in project today-framework by TAKETODAY.
the class CallCountingInterceptor method testMatchWithTypePattern.
@Test
public void testMatchWithTypePattern() throws Exception {
String expression = "execution(* *..TestBean.*Age(..))";
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(int) method").isTrue();
}
use of cn.taketoday.aop.ClassFilter in project today-framework 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\\]$");
}
use of cn.taketoday.aop.ClassFilter in project today-framework by TAKETODAY.
the class ClassFiltersTests method intersection.
@Test
void intersection() {
assertThat(exceptionFilter.matches(RuntimeException.class)).isTrue();
assertThat(hasRootCauseFilter.matches(NestedRuntimeException.class)).isTrue();
ClassFilter intersection = ClassFilters.intersection(exceptionFilter, hasRootCauseFilter);
assertThat(intersection.matches(RuntimeException.class)).isFalse();
assertThat(intersection.matches(TestBean.class)).isFalse();
assertThat(intersection.matches(NestedRuntimeException.class)).isTrue();
assertThat(intersection.toString()).matches("^.+IntersectionClassFilter: \\[.+RootClassFilter: .+Exception, .+RootClassFilter: .+NestedRuntimeException\\]$");
}
Aggregations