return enhancer;
}
private Factory createMock(Class<?> mockClass) {
Factory mock;
try {
mock = (Factory) ObjenesisClassInstantiator.newInstance(mockClass);
} catch (InstantiationException e) {
throw new RuntimeException("Fail to instantiate mock for " + mockClass
+ " on " + System.getProperty("java.vm.vendor") + " JVM");
}
// This call is required. Cglib has some "magic code" making sure a
// callback is used by only one instance of a given class. So only the
// instance created right after registering the callback will get it.
// However, this is done in the construtor which I'm bypassing to
// allow class instantiation without calling a constructor.
// Fortunatly, the "magic code" is also called in getCallback which is
// why I'm calling it here mock.getCallback(0);
mock.getCallback(0);
return mock;
}