blob: 2016f1d4dd6001b4f02422cdddfe6185bf32de3c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
import java.lang.reflect.*;
import java.util.*;
public class Util {
public static void dumpMethods(String clazzname,String[] expectedMethods) {
List methodsFound = new ArrayList();
try {
java.lang.Class clz = Class.forName(clazzname);
Method m[] = clz.getDeclaredMethods();
System.err.println("Number of methods defined for "+clazzname+" is "+(m==null?0:m.length));
if (m!=null) {
for (int i =0;i<m.length;i++) {
String methodString = m[i].getReturnType().getName()+" "+m[i].getDeclaringClass().getName()+"."+
m[i].getName()+"("+stringify(m[i].getParameterTypes())+")"+
(m[i].isBridge()?" [BridgeMethod]":"");
methodsFound.add(methodString);
}
}
} catch (Throwable e) {e.printStackTrace();}
StringBuffer diagnosticInfo = new StringBuffer();
diagnosticInfo.append("\nExpected:\n").append(dumparray(expectedMethods));
diagnosticInfo.append("\nFound:\n").append(dumplist(methodsFound));
for (int i = 0; i < expectedMethods.length; i++) {
String string = expectedMethods[i];
if (!methodsFound.contains(string)) {
throw new RuntimeException("Expecting method '"+string+"' but didnt find it\n"+diagnosticInfo.toString());
}
methodsFound.remove(string);
}
if (methodsFound.size()>0) {
throw new RuntimeException("Found more methods than expected: "+dumplist(methodsFound));
}
}
private static String dumparray(String[] arr) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < arr.length; i++) {
String string = arr[i];
sb.append(string).append("\n");
}
return sb.toString();
}
private static String dumplist(List l) {
StringBuffer sb = new StringBuffer();
for (Iterator iter = l.iterator(); iter.hasNext();) {
String element = (String) iter.next();
sb.append(element).append("\n");
}
return sb.toString();
}
private static String stringify(Class[] clazzes) {
if (clazzes==null) return "";
StringBuffer sb = new StringBuffer();
for (int i = 0; i < clazzes.length; i++) {
Class class1 = clazzes[i];
if (i>0) sb.append(",");
sb.append(clazzes[i].getName());
}
return sb.toString();
}
}
|