com.jparams.junit4.reflection.Reflection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jparams-junit4 Show documentation
Show all versions of jparams-junit4 Show documentation
Parameterized JUnit4 Tests
package com.jparams.junit4.reflection;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
public class Reflection {
private Reflection() {
}
public static MethodParameter[] getMethodParameters(Method method) {
Class>[] parameterTypes = method.getParameterTypes();
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
MethodParameter[] methodParameters = new MethodParameter[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
methodParameters[i] = new MethodParameter(parameterTypes[i], parameterAnnotations[i]);
}
return methodParameters;
}
public static T createInstance(Class clazz) {
try {
return clazz.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new InstanceCreationException("Error instantiating class " + clazz.getSimpleName(), e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy