From 3657693913b78f93a69991907fbf946d72203386 Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 18 Mar 2009 17:39:05 +0000 Subject: [PATCH] 268419: testcode: dynamic proxies and generics --- .../org/aspectj/weaver/AllWeaver5Tests.java | 3 +- .../JoinPointSignatureIteratorTests.java | 107 ++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 weaver5/java5-testsrc/org/aspectj/weaver/JoinPointSignatureIteratorTests.java diff --git a/weaver5/java5-testsrc/org/aspectj/weaver/AllWeaver5Tests.java b/weaver5/java5-testsrc/org/aspectj/weaver/AllWeaver5Tests.java index 48d981b60..54f35656f 100644 --- a/weaver5/java5-testsrc/org/aspectj/weaver/AllWeaver5Tests.java +++ b/weaver5/java5-testsrc/org/aspectj/weaver/AllWeaver5Tests.java @@ -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 index 000000000..bdc4abe0a --- /dev/null +++ b/weaver5/java5-testsrc/org/aspectj/weaver/JoinPointSignatureIteratorTests.java @@ -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); + } +} -- 2.39.5