This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ch06.springbook.aop; | ||
|
||
public class Bean { | ||
public void method() throws RuntimeException { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ch06.springbook.aop; | ||
|
||
public class Target implements TargetInterface { | ||
|
||
public void hello() {} | ||
public void hello(String a) {} | ||
public int minus(int a, int b) throws RuntimeException { return 0; } | ||
public int plus(int a, int b) { return 0; } | ||
public void method() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ch06.springbook.aop; | ||
|
||
public interface TargetInterface { | ||
void hello(); | ||
void hello(String a); | ||
int minus(int a, int b) throws RuntimeException; | ||
int plus(int a, int b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ch06.springbook.aop; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import org.junit.Test; | ||
import org.springframework.aop.aspectj.AspectJExpressionPointcut; | ||
|
||
public class AopTest { | ||
|
||
@Test | ||
public void methodSignaturePointcut() throws SecurityException, NoSuchMethodException { | ||
|
||
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); | ||
pointcut.setExpression( | ||
"execution(public int ch06.springbook.aop.Target.minus(int, int) throws java.lang.RuntimeException)"); | ||
|
||
assertThat(pointcut.getClassFilter().matches(Target.class) && | ||
pointcut.getMethodMatcher().matches(Target.class.getMethod("minus", int.class, int.class), null), is(true)); | ||
|
||
assertThat(pointcut.getClassFilter().matches(Target.class) && | ||
pointcut.getMethodMatcher().matches(Target.class.getMethod("plus", int.class, int.class), null), is(false)); | ||
|
||
assertThat(pointcut.getClassFilter().matches(Bean.class) && | ||
pointcut.getMethodMatcher().matches(Target.class.getMethod("method"), null), is(false)); | ||
} | ||
} |