Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
[ch06] Pointcut execution expression test.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhsim86 committed Sep 13, 2017
1 parent ac34917 commit 5e2b189
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/test/java/ch06/springbook/aop/AopTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,46 @@ public void methodSignaturePointcut() throws SecurityException, NoSuchMethodExce
assertThat(pointcut.getClassFilter().matches(Bean.class) &&
pointcut.getMethodMatcher().matches(Target.class.getMethod("minus", int.class, int.class), null), is(false));
}

@Test
public void pointcutTest() throws Exception {
targetClassPointcutMatches("execution(* *(..))", true, true, true, true, true, true);
targetClassPointcutMatches("execution(* hello(..))", true, true, false, false, false, false);
targetClassPointcutMatches("execution(* hello())", true, false, false, false, false, false);
targetClassPointcutMatches("execution(* hello(String))", false, true, false, false, false, false);
targetClassPointcutMatches("execution(* meth*(..))", false, false, false, false, true, true);
targetClassPointcutMatches("execution(* *(int, int))", false, false, true, true, false, false);
targetClassPointcutMatches("execution(* *())", true, false, false, false, true, true);
targetClassPointcutMatches("execution(* ch06.springbook.aop.Target.*(..))", true, true, true, true, true, false);
targetClassPointcutMatches("execution(* ch06.springbook.aop.*.*(..))", true, true, true, true, true, true);
targetClassPointcutMatches("execution(* ch06.springbook.aop..*.*(..))", true, true, true, true, true, true);
targetClassPointcutMatches("execution(* ch06..*.*(..))", true, true, true, true, true, true);
targetClassPointcutMatches("execution(* com..*.*(..))", false, false, false, false, false, false);
targetClassPointcutMatches("execution(* *..Target.*(..))", true, true, true, true, true, false);
targetClassPointcutMatches("execution(* *..Tar*.*(..))", true, true, true, true, true, false);
targetClassPointcutMatches("execution(* *..*get.*(..))", true, true, true, true, true, false);
targetClassPointcutMatches("execution(* *..B*.*(..))", false, false, false, false, false, true);
targetClassPointcutMatches("execution(* *..TargetInterface.*(..))", true, true, true, true, false, false);
targetClassPointcutMatches("execution(* *(..) throws Runtime*)", false, false, false, true, false, true);
targetClassPointcutMatches("execution(int *(..))", false, false, true, true, false, false);
targetClassPointcutMatches("execution(void *(..))", true, true, false, false, true, true);
}

public void targetClassPointcutMatches(String expression, boolean ... expected) throws Exception {
pointcutMatches(expression, expected[0], Target.class, "hello");
pointcutMatches(expression, expected[1], Target.class, "hello", String.class);
pointcutMatches(expression, expected[2], Target.class, "plus", int.class, int.class);
pointcutMatches(expression, expected[3], Target.class, "minus", int.class, int.class);
pointcutMatches(expression, expected[4], Target.class, "method");
pointcutMatches(expression, expected[5], Bean.class, "method");
}

public void pointcutMatches(String expression, Boolean expected, Class<?> clazz, String methodName, Class<?>... args) throws Exception {

AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(expression);

assertThat(pointcut.getClassFilter().matches(clazz) &&
pointcut.getMethodMatcher().matches(clazz.getMethod(methodName, args), null), is(expected));
}
}

0 comments on commit 5e2b189

Please sign in to comment.