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
| import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*;
public class EntityVoTestUtils {
private static final Map<String, Object> STATIC_MAP = new HashMap<String, Object>();
private static final String NO_NOTICE = "getClass,notify,notifyAll,wait,equals,hashCode,clone";
static { STATIC_MAP.put("java.lang.Long", 1L); STATIC_MAP.put("java.lang.String", "test"); STATIC_MAP.put("java.lang.Integer", 1); STATIC_MAP.put("int", 1); STATIC_MAP.put("long", 1); STATIC_MAP.put("java.util.Date", new Date()); STATIC_MAP.put("char", '1'); STATIC_MAP.put("java.util.Map", new HashMap()); STATIC_MAP.put("boolean", true);
}
public static void justRun(List<Class> CLASS_LIST) throws IllegalAccessException, InvocationTargetException, InstantiationException { for (Class temp : CLASS_LIST) { Object tempInstance = new Object(); Constructor[] constructors = temp.getConstructors(); for (Constructor constructor : constructors) { final Class<?>[] parameterTypes = constructor.getParameterTypes(); if (parameterTypes.length == 0) { tempInstance = constructor.newInstance(); } else { Object[] objects = new Object[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; i++) { objects[i] = STATIC_MAP.get(parameterTypes[i].getName()); } tempInstance = constructor.newInstance(objects); } }
Method[] methods = temp.getMethods(); for (final Method method : methods) { if (NO_NOTICE.contains(method.getName())) { break; } final Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length != 0) { Object[] objects = new Object[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; i++) { objects[i] = STATIC_MAP.get(parameterTypes[i].getName()); } method.invoke(tempInstance, objects); } else { method.invoke(tempInstance); } }
} } }
|