01: package com.mockrunner.test.gen;
02:
03: import java.lang.reflect.Method;
04: import java.net.URL;
05:
06: import com.mockrunner.gen.proc.BCELClassAnalyzer;
07:
08: import junit.framework.TestCase;
09:
10: public class BCELClassAnalyzerTest extends TestCase {
11: private BCELClassAnalyzer analyzer;
12: private Class theClass;
13:
14: public void testIsMethodDeprecated() {
15: theClass = MyTestClass.class;
16: analyzer = new BCELClassAnalyzer(theClass);
17: assertDeprecated("method1", false);
18: assertDeprecated("method3", true);
19: assertDeprecated("method4", false);
20: checkMethod2();
21: theClass = Thread.class;
22: analyzer = new BCELClassAnalyzer(theClass);
23: assertDeprecated("resume", true);
24: assertDeprecated("run", false);
25: }
26:
27: private void checkMethod2() {
28: Method[] methods = theClass.getDeclaredMethods();
29: for (int ii = 0; ii < methods.length; ii++) {
30: if (methods[ii].getName().equals("method2")) {
31: boolean isDeprecated = analyzer
32: .isMethodDeprecated(methods[ii]);
33: if (methods[ii].getParameterTypes()[0]
34: .equals(String.class)) {
35: assertTrue(isDeprecated);
36: } else {
37: assertFalse(isDeprecated);
38: }
39: }
40: }
41: }
42:
43: private void assertDeprecated(String methodName,
44: boolean shouldBeDeprecated) {
45: Method[] methods = theClass.getDeclaredMethods();
46: for (int ii = 0; ii < methods.length; ii++) {
47: if (methodName.equals(methods[ii].getName())) {
48: boolean isDeprecated = analyzer
49: .isMethodDeprecated(methods[ii]);
50: assertTrue(isDeprecated == shouldBeDeprecated);
51: }
52: }
53: }
54:
55: private class MyTestClass {
56: public void method1() {
57:
58: }
59:
60: /**
61: * @deprecated
62: */
63: protected String method2(String aString) {
64: return null;
65: }
66:
67: protected String method2(String[] aStringArray) {
68: return null;
69: }
70:
71: /**
72: * @deprecated
73: */
74: public BCELClassAnalyzerTest method3(int[][] anIntArray,
75: double aDouble) throws Exception {
76: method4(null);
77: return null;
78: }
79:
80: private void method4(URL[] urls) throws Exception {
81:
82: }
83: }
84: }
|