Hi. I am trying to write some code that will increase my code coverage by traversing my project and inspecting each class for getters, setters and booleans. The program should invoke these methods under junit. However, I've hit a snag. What if my code calls for a setMethod(int x) or setMethod(char c)? The code below will not work with primitives (it throws an IllegalArgumentException). Could someone tell me how to fix this, please?
void invokeAMethod(Object object, Method method, Class[] paramTypes) {
String params = "";
for (Class myclass : paramTypes) {
params += myclass + " ";
}
try {
Object returnValue = method.invoke(object, params);
System.out.println("done with " + method.getName());
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}