From 1381903ac81cdab2b79b6525096671aa5d62eaeb Mon Sep 17 00:00:00 2001 From: acolyer Date: Fri, 11 Feb 2005 12:47:56 +0000 Subject: move all java 5 tests out of code and back into .xml files now that we can compile them properly --- .../annotations/thisOrtarget/ThisOrTargetTests.aj | 49 ++++++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'tests/java5/annotations') diff --git a/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj b/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj index cc5ab5cd0..2936b2ec5 100644 --- a/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj +++ b/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj @@ -1,7 +1,18 @@ import java.util.List; +import java.util.ArrayList; +import java.util.Iterator; +import org.aspectj.lang.JoinPoint.StaticPart; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.Signature; public aspect ThisOrTargetTests { + List before1Matches = new ArrayList(); + List before2Matches = new ArrayList(); + List after1Matches = new ArrayList(); + List after2Matches = new ArrayList(); + + pointcut doSomethingExecution() : execution(* doSomething()); pointcut doSomethingCall() : call(* doSomething()); @@ -9,7 +20,7 @@ public aspect ThisOrTargetTests { // should match: // b.doSomething(), reallyB.doSomething() [with test], // c.doSomething() - System.out.println("@this(@MyAnnotation): " + thisJoinPointStaticPart); + add(before1Matches,thisJoinPointStaticPart); } before() : doSomethingExecution() && @this(@MyInheritableAnnotation) { @@ -17,14 +28,14 @@ public aspect ThisOrTargetTests { // c.doSomething() // d.doSomething() // reallyD.doSomething() - System.out.println("@this(@MyInheritableAnnotation): " + thisJoinPointStaticPart); + add(before2Matches,thisJoinPointStaticPart); } after() returning : doSomethingCall() && @target(@MyAnnotation) { // should match: // b.doSomething(), reallyB.doSomething() [with test], // c.doSomething() - System.out.println("@target(@MyAnnotation): " + thisJoinPointStaticPart); + add(after1Matches,thisJoinPointStaticPart); } after() returning : doSomethingCall() && @target(@MyInheritableAnnotation) { @@ -32,7 +43,37 @@ public aspect ThisOrTargetTests { // c.doSomething() // d.doSomething() // reallyD.doSomething() - System.out.println("@target(@MyInheritableAnnotation): " + thisJoinPointStaticPart); + add(after2Matches,thisJoinPointStaticPart); } + private void add(List toList, JoinPoint.StaticPart jpsp) { + Signature sig = jpsp.getSignature(); + String toAdd = sig.getDeclaringTypeName() + "." + sig.getName(); + toList.add(toAdd); + } + + after() returning : execution(* main(String[])) { + assertMatches("before1",before1Matches, + new String[] {"B.doSomething","C.doSomething","B.doSomething"} ); + assertMatches("before2",before2Matches, + new String[] {"C.doSomething","D.doSomething","D.doSomething"} ); + assertMatches("after1",after1Matches, + new String[] {"B.doSomething","C.doSomething","A.doSomething"} ); + assertMatches("after2",after2Matches, + new String[] {"C.doSomething","D.doSomething","C.doSomething"} ); + } + + private void assertMatches(String name, List matches,String[] spec) { + if (matches.size() != spec.length) { + for (Iterator iter = matches.iterator(); iter.hasNext();) { + String match = iter.next(); + System.out.println(match); + } + + throw new RuntimeException(name + ": Expected " + spec.length + " matches, got " + matches.size()); + } + for (int i = 0; i < spec.length; i++) { + if (!matches.get(i).equals(spec[i])) throw new RuntimeException(name + ":Excepted " + spec[i] + " got " + matches.get(i)); + } + } } \ No newline at end of file -- cgit v1.2.3