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.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhsim86 committed Sep 12, 2017
1 parent 10c3db6 commit a341034
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<version>${spring.framework-version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.framework-version}</version>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ch06/springbook/aop/Bean.java
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 {

}
}
10 changes: 10 additions & 0 deletions src/main/java/ch06/springbook/aop/Target.java
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() {}
}
8 changes: 8 additions & 0 deletions src/main/java/ch06/springbook/aop/TargetInterface.java
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);
}
27 changes: 27 additions & 0 deletions src/test/java/ch06/springbook/aop/AopTest.java
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));
}
}

0 comments on commit a341034

Please sign in to comment.