cucumber.runtime.Utils Maven / Gradle / Ivy
package cucumber.runtime;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Utils {
public static List listOf(int size, T obj) {
List list = new ArrayList();
for (int i = 0; i < size; i++) {
list.add(obj);
}
return list;
}
public static boolean isInstantiable(Class> clazz) {
boolean isNonStaticInnerClass = !Modifier.isStatic(clazz.getModifiers()) && clazz.getEnclosingClass() != null;
return Modifier.isPublic(clazz.getModifiers()) && !Modifier.isAbstract(clazz.getModifiers()) && !isNonStaticInnerClass;
}
public static boolean hasConstructor(Class> clazz, Class[] paramTypes) {
try {
clazz.getConstructor(paramTypes);
return true;
} catch (NoSuchMethodException e) {
return false;
}
}
public static Object invoke(final Object target, final Method method, int timeoutMillis, final Object... args) throws Throwable {
return Timeout.timeout(new Timeout.Callback