use of org.powermock.api.mockito.repackaged.cglib.proxy.Factory in project powermock by powermock.
the class CglibMockMaker method getHandler.
public MockHandler getHandler(Object mock) {
if (!(mock instanceof Factory)) {
return null;
}
Factory factory = (Factory) mock;
Callback callback = factory.getCallback(0);
if (!(callback instanceof MethodInterceptorFilter)) {
return null;
}
return ((MethodInterceptorFilter) callback).getHandler();
}
use of org.powermock.api.mockito.repackaged.cglib.proxy.Factory in project powermock by powermock.
the class ClassImposterizer method imposterise.
public <T> T imposterise(final MethodInterceptor interceptor, Class<T> mockedType, Class<?>... ancillaryTypes) {
Class<Factory> proxyClass = null;
Object proxyInstance = null;
try {
setConstructorsAccessible(mockedType, true);
proxyClass = createProxyClass(mockedType, ancillaryTypes);
proxyInstance = createProxy(proxyClass, interceptor);
return mockedType.cast(proxyInstance);
} catch (ClassCastException cce) {
throw new MockitoException(join("ClassCastException occurred while creating the mockito proxy :", " class to mock : " + describeClass(mockedType), " created class : " + describeClass(proxyClass), " proxy instance class : " + describeClass(proxyInstance), " instance creation by : " + instantiator.getClass().getSimpleName(), "", "You might experience classloading issues, disabling the Objenesis cache *might* help (see MockitoConfiguration)"), cce);
} finally {
setConstructorsAccessible(mockedType, false);
}
}
use of org.powermock.api.mockito.repackaged.cglib.proxy.Factory 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