use of org.mockito.internal.creation.instance.InstantiationException in project mockito by mockito.
the class JavaEightUtil method invokeNullaryFactoryMethod.
/**
* Invokes a nullary static factory method using reflection to stay backwards-compatible with older JDKs.
*
* @param fqcn The fully qualified class name of the type to be produced.
* @param methodName The name of the factory method.
* @return the object produced.
*/
private static Object invokeNullaryFactoryMethod(final String fqcn, final String methodName) {
try {
final Class<?> type = Class.forName(fqcn);
final Method method = type.getMethod(methodName);
return method.invoke(null);
// any exception is really unexpected since the type name has
// already been verified
} catch (final Exception e) {
throw new InstantiationException(String.format("Could not create %s#%s(): %s", fqcn, methodName, e), e);
}
}
use of org.mockito.internal.creation.instance.InstantiationException in project powermock by powermock.
the class ClassImposterizer method createProxy.
private Object createProxy(Class<Factory> proxyClass, final MethodInterceptor interceptor) {
Factory proxy;
try {
proxy = instantiator.newInstance(proxyClass);
} catch (InstantiationException e) {
throw new MockitoException("Unable to create mock instance of type '" + proxyClass.getSuperclass().getSimpleName() + "'", e);
}
proxy.setCallbacks(new Callback[] { interceptor, SerializableNoOp.SERIALIZABLE_INSTANCE });
return proxy;
}
Aggregations