]> source.dussan.org Git - aspectj.git/commitdiff
268419: testcode: dynamic proxies and generics
authoraclement <aclement>
Wed, 18 Mar 2009 17:39:05 +0000 (17:39 +0000)
committeraclement <aclement>
Wed, 18 Mar 2009 17:39:05 +0000 (17:39 +0000)
weaver5/java5-testsrc/org/aspectj/weaver/AllWeaver5Tests.java
weaver5/java5-testsrc/org/aspectj/weaver/JoinPointSignatureIteratorTests.java [new file with mode: 0644]

index 48d981b603001b7b2d306c2687ab362a2fb9917f..54f35656f285003ff3622a10f93550c241704e3d 100644 (file)
@@ -28,8 +28,9 @@ public class AllWeaver5Tests {
                suite.addTest(BcweaverModuleTests15.suite());
                suite.addTestSuite(ReflectionWorldReferenceTypeTest.class);
                suite.addTestSuite(PointcutExpressionTest.class);
+               suite.addTestSuite(JoinPointSignatureIteratorTests.class);
                // gives incompatible class version error...
-               //suite.addTestSuite(ReflectionWorldAdvancedPointcutExpressionTests.class
+               // suite.addTestSuite(ReflectionWorldAdvancedPointcutExpressionTests.class
                // );
                suite.addTestSuite(ReflectionWorldSpecificTest.class);
                // $JUnit-END$
diff --git a/weaver5/java5-testsrc/org/aspectj/weaver/JoinPointSignatureIteratorTests.java b/weaver5/java5-testsrc/org/aspectj/weaver/JoinPointSignatureIteratorTests.java
new file mode 100644 (file)
index 0000000..bdc4abe
--- /dev/null
@@ -0,0 +1,107 @@
+/* *******************************************************************
+ * Copyright (c) 2009 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: 
+ *   Andy Clement
+ * ******************************************************************/
+package org.aspectj.weaver;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.aspectj.weaver.reflect.ReflectionWorld;
+
+/**
+ * @author Andy Clement
+ */
+public class JoinPointSignatureIteratorTests extends TestCase {
+
+       private World getWorld() {
+               return new ReflectionWorld(getClass().getClassLoader());
+       }
+
+       /**
+        * Checking the signatures for a dynamic proxy - which is created using erased information and so is completely generics unaware
+        */
+       public void testPr268419() {
+               World w = getWorld();
+               w.setBehaveInJava5Way(true);
+
+               // The proxy class here is not generated, it is simply loaded up. $Proxy1 is in the java5-testsrc folder, but it
+               // obeys the rules of a generated proxy in that it extends java.lang.reflect.Proxy
+               ResolvedType proxy = UnresolvedType.forName("$Proxy1").resolve(w);
+               assertNotNull(proxy);
+
+               // The test hierarchy here (messageservice and genericservice) contains 2 methods. One is generic
+               // and one is not. The aim of the test here is that the join point signatures generated for both
+               // should be the same because of the use of a proxy.
+
+               List l = proxy.getMethodsWithoutIterator(false, false);
+               for (Object object : l) {
+                       ResolvedMember rm = (ResolvedMember) object;
+                       if (expectedResults.containsKey(rm.toString())) {
+                               System.out.println("\nChecking: " + rm);
+                               int i = 0;
+                               List/* String */sigs = (List) expectedResults.get(rm.toString());
+                               Iterator jpsi = rm.getJoinPointSignatures(w);
+                               while (jpsi.hasNext()) {
+                                       ResolvedMember sig = (ResolvedMember) jpsi.next();
+                                       assertEquals(sigs.get(i).toString(), sig.toString());
+                                       i++;
+                               }
+                               if (i != sigs.size()) {
+                                       fail("Expected " + sigs.size() + " signatures but got " + i);
+                               }
+                       } else {
+                               if (rm.getName().equals("get1") || rm.getName().equals("get2")) {
+                                       fail("\nFound this unchecked get method " + rm);
+                                       // Iterator jpsi = rm.getJoinPointSignatures(w);
+                                       // while (jpsi.hasNext()) {
+                                       // ResolvedMember sig = (ResolvedMember) jpsi.next();
+                                       // System.out.println(sig);
+                                       // }
+                               }
+                       }
+               }
+       }
+
+       public static Map expectedResults = new HashMap();
+
+       static {
+               List sigs = new ArrayList();
+               sigs.add("java.lang.Object $Proxy1.get1(java.io.Serializable)");
+               sigs.add("java.lang.Object MessageService.get1(java.io.Serializable)");
+               sigs.add("java.lang.Object GenericService.get1(java.io.Serializable)");
+               sigs.add("java.lang.Object GenericService.get1(java.io.Serializable)");
+               expectedResults.put("java.lang.Object $Proxy1.get1(java.io.Serializable)", sigs);
+
+               sigs = new ArrayList();
+               sigs.add("java.lang.Object $Proxy1.get2(java.io.Serializable)");
+               sigs.add("java.lang.Object MessageService.get2(java.io.Serializable)");
+               sigs.add("java.lang.Object GenericService.get2(java.io.Serializable)");
+               sigs.add("java.lang.Object GenericService.get2(java.io.Serializable)");
+               expectedResults.put("java.lang.Object $Proxy1.get2(java.io.Serializable)", sigs);
+
+               sigs = new ArrayList();
+               sigs.add("java.lang.Object $Proxy1.get1(java.lang.Long)");
+               expectedResults.put("java.lang.Object $Proxy1.get1(java.lang.Long)", sigs);
+
+               sigs = new ArrayList();
+               sigs.add("java.lang.Object GenericService.get1(java.io.Serializable)");
+               expectedResults.put("java.lang.Object GenericService.get1(java.io.Serializable)", sigs);
+
+               sigs = new ArrayList();
+               sigs.add("java.lang.Object GenericService.get2(java.io.Serializable)");
+               expectedResults.put("java.lang.Object GenericService.get2(java.io.Serializable)", sigs);
+       }
+}