FileDocCategorySizeDatePackage
TestParamNameExtractor.javaAPI DocApache Axis 1.43458Sat Apr 22 18:57:28 BST 2006test.utils.bytecode

TestParamNameExtractor

public class TestParamNameExtractor extends TestCase
Description User: pengyu Date: Sep 12, 2003 Time: 11:47:48 PM

Fields Summary
TestClass
t
Constructors Summary
public TestParamNameExtractor(String name)


       
        super(name);
    
Methods Summary
protected voidsetup()

        t = this.new TestClass();
    
public static junit.framework.Testsuite()

        return new TestSuite(TestParamNameExtractor.class);
    
public voidtestExtractOverloadedParameter()

        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"));
            }
        }
    
public voidtestExtractParameter()

        //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"));