1 4 package com.tc.object.bytecode.aspectwerkz; 5 6 import com.tc.aspectwerkz.reflect.ClassInfo; 7 import com.tc.aspectwerkz.reflect.MethodInfo; 8 import com.tc.aspectwerkz.reflect.impl.java.JavaMethodInfo; 9 import com.tc.object.BaseDSOTestCase; 10 import com.tc.object.config.DSOClientConfigHelper; 11 import com.tctest.AsmMethodInfoTestHelper; 12 13 import java.lang.reflect.Method ; 14 15 18 public class AsmMethodInfoTest extends BaseDSOTestCase { 19 20 AsmMethodInfo methodInfo; 21 MethodInfo javaMethodInfo; 22 DSOClientConfigHelper config; 23 24 private void setUp(Method method) throws Exception { 25 this.methodInfo = AsmMethodInfo.createNewAsmMethodInfo(method); 26 javaMethodInfo = JavaMethodInfo.getMethodInfo(method); 27 config = configHelper(); 28 } 29 30 public void testAsmMethodInfoTestHelperTest4() throws Exception { 31 Method method = AsmMethodInfoTestHelper.class.getMethod("test4", new Class [] { Integer.TYPE, Object .class }); 32 setUp(method); 33 assertTrue(compareMethodInfos(this.javaMethodInfo, this.methodInfo)); 34 35 String expression = "long " + AsmMethodInfoTestHelper.class.getName() + "." + method.getName() 36 + "(int, java.lang.Object)"; 37 assertTrue(config.matches(expression, this.javaMethodInfo)); 38 assertTrue(config.matches(expression, this.methodInfo)); 39 } 40 41 public void publicVoidTestMethod() throws Exception { 42 } 43 44 public void testPublicVoidTestMethod() throws Exception { 45 Method method = getClass().getMethod("publicVoidTestMethod", new Class [0]); 46 setUp(method); 47 assertTrue(compareMethodInfos(this.javaMethodInfo, this.methodInfo)); 48 } 49 50 public void testPublicVoidTestMethodMatch() throws Exception { 51 String methodName = "publicVoidTestMethod"; 52 Method method = getClass().getMethod(methodName, new Class [0]); 53 setUp(method); 54 String expression = "* " + getClass().getName() + "." + methodName + "()"; 55 assertTrue(config.matches(expression, this.javaMethodInfo)); 56 assertTrue(config.matches(expression, this.methodInfo)); 57 } 58 59 public void publicVoidTestMethodStringInt(String string, int i) throws Exception { 60 } 61 62 public void testPublicVoidTestMethodStringInt() throws Exception { 63 Method method = getClass().getMethod("publicVoidTestMethodStringInt", new Class [] { String .class, Integer.TYPE }); 64 setUp(method); 65 assertTrue(compareMethodInfos(this.javaMethodInfo, this.methodInfo)); 66 } 67 68 public long[][][] publicLong3TestMethodDouble4(double[][][][] double4) throws Exception { 69 return null; 70 } 71 72 public void testPublicLong3TestMethodDouble4() throws Exception { 73 Method method = getClass().getMethod("publicLong3TestMethodDouble4", new Class [] { double[][][][].class }); 74 setUp(method); 75 assertTrue(compareMethodInfos(this.javaMethodInfo, this.methodInfo)); 76 77 } 78 79 private static boolean compareMethodInfos(MethodInfo source, MethodInfo target) { 80 if (source.getModifiers() != target.getModifiers()) { return false; } 84 if (!source.getName().equals(target.getName())) { return false; } 85 if (!compareClassInfos(source.getDeclaringType(), target.getDeclaringType())) { return false; } 87 if (!compareClassInfos(source.getReturnType(), target.getReturnType())) { return false; } 89 if (!(source.getParameterTypes().length == target.getParameterTypes().length)) { return false; } 91 for (int i = 0; i < source.getParameterTypes().length; i++) { 92 if (!compareClassInfos(source.getParameterTypes()[i], target.getParameterTypes()[i])) { return false; } 93 } 94 if (!(source.getExceptionTypes().length == target.getExceptionTypes().length)) { return false; } 95 for (int i = 0; i < source.getExceptionTypes().length; i++) { 99 if (!compareClassInfos(source.getExceptionTypes()[i], target.getExceptionTypes()[i])) { return false; } 100 } 101 return true; 102 } 103 104 private static boolean compareClassInfos(ClassInfo source, ClassInfo target) { 105 return source.getName().equals(target.getName()); 108 } 109 110 } | Popular Tags |