aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.matcher/testsrc
diff options
context:
space:
mode:
authoraclement <aclement>2008-12-10 20:01:33 +0000
committeraclement <aclement>2008-12-10 20:01:33 +0000
commit1c5d4bc331f4273083b547923b122571b8387bfe (patch)
treed4882a33c83596f0cd7b1b942c90178dceaedcf4 /org.aspectj.matcher/testsrc
parenta84b3a8bb1904644942ed38277960ebd97bd9b51 (diff)
downloadaspectj-1c5d4bc331f4273083b547923b122571b8387bfe.tar.gz
aspectj-1c5d4bc331f4273083b547923b122571b8387bfe.zip
some annotation matching tests
Diffstat (limited to 'org.aspectj.matcher/testsrc')
-rw-r--r--org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/CommonAdvancedPointcutExpressionTests.java (renamed from org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/FurtherCommonPointcutExpressionTests.java)55
1 files changed, 46 insertions, 9 deletions
diff --git a/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/FurtherCommonPointcutExpressionTests.java b/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/CommonAdvancedPointcutExpressionTests.java
index 03860c008..e5fa8b0c0 100644
--- a/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/FurtherCommonPointcutExpressionTests.java
+++ b/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/CommonAdvancedPointcutExpressionTests.java
@@ -25,9 +25,17 @@ import org.aspectj.weaver.tools.StandardPointcutParser;
*
* This is based on the Reflection oriented PointcutExpressionTest in the weaver project.
*
+ * TESTDATA. The testdata for these tests is kept in org.aspectj.matcher/testdata. It is a series of .java files that need to be
+ * compiled and available at runtime. Since they are java5 (they include annotations) they cannot be in a source folder for the
+ * project, so they are compiled separately and then jar'd into a testdata.jar file in that folder. This folder is defined to be on
+ * the classpath for org.aspectj.matcher, this enables them to be seen by a simple world that uses the classpath of the matcher
+ * project as the definition of what it can see. Other worlds, for example JDT World, will need to have those types defined in a
+ * project that is accessible in the JDT World instance. Because these tests exercise Java5 matching, the concrete ReflectionWorld
+ * subtype is not defined in here, it is defined in weaver5 (messy, but works well).
+ *
* @author Andy Clement
*/
-public abstract class FurtherCommonPointcutExpressionTests extends TestCase {
+public abstract class CommonAdvancedPointcutExpressionTests extends TestCase {
private World world;
private StandardPointcutParser pointcutParser;
@@ -40,15 +48,44 @@ public abstract class FurtherCommonPointcutExpressionTests extends TestCase {
pointcutParser = StandardPointcutParser.getPointcutParserSupportingAllPrimitives(world);
}
- // public void testResolvingOneType() {
- // // do it via name
- // ResolvedType type = world.resolve("java.lang.String");
- // assertNotNull(type);
- // // do it via signature
- // type = world.resolve(UnresolvedType.forSignature("Ljava/lang/String;"));
- // assertNotNull(type);
- // }
+ public void testResolvingOneType() {
+ assertFalse(world.resolve("testdata.SomeAnnotation").isMissing());
+ assertFalse(world.resolve("testdata.MethodLevelAnnotation").isMissing());
+ assertFalse(world.resolve("testdata.AnnotatedClass").isMissing());
+ }
+
+ public void testTypeLevelAnnotationMatchingWithStaticInitialization01() {
+ StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("staticinitialization(@testdata.SomeAnnotation *)");
+ ResolvedType jlString = world.resolve("java.lang.String");
+ ResolvedType tAnnotatedClass = world.resolve("testdata.AnnotatedClass");
+
+ assertTrue(ex.matchesStaticInitialization(tAnnotatedClass).alwaysMatches());
+ assertTrue(ex.matchesStaticInitialization(jlString).neverMatches());
+ }
+
+ public void testTypeLevelAnnotationMatchingWithExecution01() {
+ StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("execution(* (@testdata.SomeAnnotation *).*(..))");
+ ResolvedType jlString = world.resolve("java.lang.String");
+ ResolvedType tAnnotatedClass = world.resolve("testdata.AnnotatedClass");
+ assertTrue(ex.matchesMethodExecution(getMethod(tAnnotatedClass, "annotatedMethod", "()V")).alwaysMatches());
+ assertTrue(ex.matchesMethodExecution(getMethod(jlString, "valueOf", "(Z)Ljava/lang/String;")).neverMatches());
+ }
+
+ public void testMethodLevelAnnotationMatchingWithExecution01() {
+ StandardPointcutExpression ex = pointcutParser
+ .parsePointcutExpression("execution(@testdata.MethodLevelAnnotation * *(..))");
+ ResolvedType jlString = world.resolve("java.lang.String");
+ ResolvedType tAnnotatedClass = world.resolve("testdata.AnnotatedClass");
+ assertTrue(ex.matchesMethodExecution(getMethod(tAnnotatedClass, "annotatedMethod", "()V")).alwaysMatches());
+ assertTrue(ex.matchesMethodExecution(getMethod(tAnnotatedClass, "nonAnnotatedMethod", "()V")).neverMatches());
+ assertTrue(ex.matchesMethodExecution(getMethod(jlString, "valueOf", "(Z)Ljava/lang/String;")).neverMatches());
+ }
+
//
+ // ResolvedMember stringSplitMethod = getMethod(jlString, "split", "(Ljava/lang/String;I)[Ljava/lang/String;");
+ // ResolvedMember stringValueOfIntMethod = getMethod(jlString, "valueOf", "(I)Ljava/lang/String;");
+ // ResolvedMember listAddMethod = getMethod(juList, "add", "(Ljava/lang/Object;)Z");
+
// public void testResolveTypeAndRetrieveMethod() {
// ResolvedType type = world.resolve("java.lang.String");
// assertNotNull(type);