use of org.mockito.internal.creation.instance.ConstructorInstantiator in project mockito by mockito.
the class InlineDelegateByteBuddyMockMaker method doCreateMock.
private <T> T doCreateMock(MockCreationSettings<T> settings, MockHandler handler, boolean nullOnNonInlineConstruction) {
Class<? extends T> type = createMockType(settings);
try {
T instance;
if (settings.isUsingConstructor()) {
instance = new ConstructorInstantiator(settings.getOuterClassInstance() != null, settings.getConstructorArgs()).newInstance(type);
} else {
try {
// We attempt to use the "native" mock maker first that avoids
// Objenesis and Unsafe
instance = newInstance(type);
} catch (InstantiationException ignored) {
if (nullOnNonInlineConstruction) {
return null;
}
Instantiator instantiator = Plugins.getInstantiatorProvider().getInstantiator(settings);
instance = instantiator.newInstance(type);
}
}
MockMethodInterceptor mockMethodInterceptor = new MockMethodInterceptor(handler, settings);
mocks.put(instance, mockMethodInterceptor);
if (instance instanceof MockAccess) {
((MockAccess) instance).setMockitoInterceptor(mockMethodInterceptor);
}
return instance;
} catch (InstantiationException e) {
throw new MockitoException("Unable to create mock instance of type '" + type.getSimpleName() + "'", e);
}
}
Aggregations