TestParamNameExtractorpublic class TestParamNameExtractor extends TestCase Description
User: pengyu
Date: Sep 12, 2003
Time: 11:47:48 PM |
Constructors Summary |
---|
public TestParamNameExtractor(String name)
super(name);
|
Methods Summary |
---|
protected void | setup()
t = this.new TestClass();
| public static junit.framework.Test | suite()
return new TestSuite(TestParamNameExtractor.class);
| 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"));
}
}
| 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"));
|
|