KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > bytecode > aspectwerkz > AsmMethodInfoTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
14
15 /**
16  * Unit test for AsmMethodInfo
17  */

18 public class AsmMethodInfoTest extends BaseDSOTestCase {
19
20   AsmMethodInfo methodInfo;
21   MethodInfo javaMethodInfo;
22   DSOClientConfigHelper config;
23
24   private void setUp(Method JavaDoc method) throws Exception JavaDoc {
25     this.methodInfo = AsmMethodInfo.createNewAsmMethodInfo(method);
26     javaMethodInfo = JavaMethodInfo.getMethodInfo(method);
27     config = configHelper();
28   }
29
30   public void testAsmMethodInfoTestHelperTest4() throws Exception JavaDoc {
31     Method JavaDoc method = AsmMethodInfoTestHelper.class.getMethod("test4", new Class JavaDoc[] { Integer.TYPE, Object JavaDoc.class });
32     setUp(method);
33     assertTrue(compareMethodInfos(this.javaMethodInfo, this.methodInfo));
34
35     String JavaDoc 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 JavaDoc { /**/
42   }
43
44   public void testPublicVoidTestMethod() throws Exception JavaDoc {
45     Method JavaDoc method = getClass().getMethod("publicVoidTestMethod", new Class JavaDoc[0]);
46     setUp(method);
47     assertTrue(compareMethodInfos(this.javaMethodInfo, this.methodInfo));
48   }
49
50   public void testPublicVoidTestMethodMatch() throws Exception JavaDoc {
51     String JavaDoc methodName = "publicVoidTestMethod";
52     Method JavaDoc method = getClass().getMethod(methodName, new Class JavaDoc[0]);
53     setUp(method);
54     String JavaDoc 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 JavaDoc string, int i) throws Exception JavaDoc { /**/
60   }
61
62   public void testPublicVoidTestMethodStringInt() throws Exception JavaDoc {
63     Method JavaDoc method = getClass().getMethod("publicVoidTestMethodStringInt", new Class JavaDoc[] { String JavaDoc.class, Integer.TYPE });
64     setUp(method);
65     assertTrue(compareMethodInfos(this.javaMethodInfo, this.methodInfo));
66   }
67
68   public long[][][] publicLong3TestMethodDouble4(double[][][][] double4) throws Exception JavaDoc {
69     return null;
70   }
71
72   public void testPublicLong3TestMethodDouble4() throws Exception JavaDoc {
73     Method JavaDoc method = getClass().getMethod("publicLong3TestMethodDouble4", new Class JavaDoc[] { 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     // test the method name;
81
// System.out.println("Testing method name: " + source.getName() + ", " +
82
// target.getName());
83
if (source.getModifiers() != target.getModifiers()) { return false; }
84     if (!source.getName().equals(target.getName())) { return false; }
85     // test the class name
86
if (!compareClassInfos(source.getDeclaringType(), target.getDeclaringType())) { return false; }
87     // test the return type
88
if (!compareClassInfos(source.getReturnType(), target.getReturnType())) { return false; }
89     // test the parameter types
90
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     // XXX: If the exceptions aren't reported in the same order, this test will
96
// fail, which
97
// is probably wrong.
98
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     // System.out.println("source name: "+source.getName() + ", target name: " +
106
// target.getName());
107
return source.getName().equals(target.getName());
108   }
109
110 }
Popular Tags