File: TestParamNameExtractor.java

package info (click to toggle)
axis 1.4-29
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 52,100 kB
  • sloc: java: 129,124; xml: 10,602; jsp: 983; sh: 84; cs: 36; makefile: 18
file content (99 lines) | stat: -rw-r--r-- 3,458 bytes parent folder | download | duplicates (10)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package test.utils.bytecode;

import junit.framework.TestCase;
import junit.framework.Test;
import junit.framework.TestSuite;

import java.lang.reflect.Method;
import java.util.List;
import java.util.ArrayList;

import org.apache.axis.utils.bytecode.ParamNameExtractor;

/**
 * Description
 * User: pengyu
 * Date: Sep 12, 2003
 * Time: 11:47:48 PM
 * 
 */
public class TestParamNameExtractor extends TestCase {
    TestClass t = null;

    public TestParamNameExtractor(String name) {
        super(name);
    }

    public static Test suite() {
        return new TestSuite(TestParamNameExtractor.class);
    }

    protected void setup() {
        t = this.new TestClass();
    }

    public void testExtractParameter() {
        //now get the nonoverloadmethod
        Method[] methods = TestClass.class.getMethods();
        Method method = null;
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].getName().equals("nonOverloadMethod")) {
                method = methods[i];
            }
        }
        assertTrue("Find nonOverloadMethod", method != null);
        String[] params = ParamNameExtractor.getParameterNamesFromDebugInfo(method);
        assertTrue("Number of parameter is right", params.length == 2);
        assertTrue("First name of parameter is intValue", params[0].equals("intValue"));
        assertTrue("Second name of parameter is boolValue", params[1].equals("boolValue"));
    }

    public void testExtractOverloadedParameter() {
        Method[] methods = TestClass.class.getMethods();
        List matchMethods = new ArrayList();
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].getName().equals("overloadedMethod")) {
                matchMethods.add(methods[i]);
            }
        }
        assertTrue("Found two overloaded methods", matchMethods.size() == 2);
        boolean foundBoolean = false;
        boolean foundInt = false;
        for (int i = 0; i < 2; i++) {
            Method method = (Method) matchMethods.get(i);
            Class[] paramTypes = method.getParameterTypes();
            assertTrue("only one parameter found", paramTypes.length == 1);
            assertTrue("It has to be either boolean or int",
                    (paramTypes[0] == Integer.TYPE) ||
                    (paramTypes[0] == Boolean.TYPE));
            String[] params = ParamNameExtractor.getParameterNamesFromDebugInfo(method);
            assertTrue("Only parameter found", params.length == 1);
            if (paramTypes[0] == Integer.TYPE) {
                if (foundInt) { //already found such method so something is wrong
                    fail("It is wrong type, should not be int");
                }else {
                    foundInt = true;
                }
                assertTrue("parameter is 'intValue'", params[0].equals("intValue"));
            } else if (paramTypes[0] == Boolean.TYPE) {
                if (foundBoolean) {
                    fail("It is wrong type, should not be boolean");
                }else {
                    foundBoolean = true;
                }
                assertTrue("parameter is 'boolValue'", params[0].equals("boolValue"));
            }
        }
    }

    class TestClass {
        public void nonOverloadMethod(int intValue, boolean boolValue) {
        }

        public void overloadedMethod(int intValue) {
        }

        public void overloadedMethod(boolean boolValue) {
        }
    }
}