use of org.mockito.internal.util.MockNameImpl in project mockito by mockito.
the class MockSettingsImpl method validatedSettings.
private static <T> CreationSettings<T> validatedSettings(Class<T> typeToMock, CreationSettings<T> source) {
MockCreationValidator validator = new MockCreationValidator();
validator.validateType(typeToMock);
validator.validateExtraInterfaces(typeToMock, source.getExtraInterfaces());
validator.validateMockedType(typeToMock, source.getSpiedInstance());
//TODO SF - add this validation and also add missing coverage
// validator.validateDelegatedInstance(classToMock, settings.getDelegatedInstance());
validator.validateConstructorUse(source.isUsingConstructor(), source.getSerializableMode());
//TODO SF - I don't think we really need CreationSettings type
CreationSettings<T> settings = new CreationSettings<T>(source);
settings.setMockName(new MockNameImpl(source.getName(), typeToMock));
settings.setTypeToMock(typeToMock);
settings.setExtraInterfaces(prepareExtraInterfaces(source));
return settings;
}
use of org.mockito.internal.util.MockNameImpl in project j2objc by google.
the class MockSettingsImpl method validatedSettings.
private static <T> CreationSettings<T> validatedSettings(Class<T> typeToMock, CreationSettings<T> source) {
MockCreationValidator validator = new MockCreationValidator();
validator.validateType(typeToMock);
validator.validateExtraInterfaces(typeToMock, source.getExtraInterfaces());
validator.validateMockedType(typeToMock, source.getSpiedInstance());
//TODO SF - add this validation and also add missing coverage
// validator.validateDelegatedInstance(classToMock, settings.getDelegatedInstance());
CreationSettings<T> settings = new CreationSettings<T>(source);
settings.setMockName(new MockNameImpl(source.getName(), typeToMock));
settings.setTypeToMock(typeToMock);
settings.setExtraInterfaces(prepareExtraInterfaces(source));
return settings;
}
use of org.mockito.internal.util.MockNameImpl in project powermock by powermock.
the class DefaultMockCreator method createMethodInvocationControl.
@SuppressWarnings("unchecked")
private static <T> MockData<T> createMethodInvocationControl(final String mockName, Class<T> type, Method[] methods, boolean isSpy, Object delegator, MockSettings mockSettings) {
final MockSettingsImpl settings;
if (mockSettings == null) {
// We change the context classloader to the current CL in order for the Mockito
// framework to load it's plugins (such as MockMaker) correctly.
final ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(DefaultMockCreator.class.getClassLoader());
try {
settings = (MockSettingsImpl) Mockito.withSettings();
Plugins.getMockMaker();
} finally {
Thread.currentThread().setContextClassLoader(originalCL);
}
} else {
settings = (MockSettingsImpl) mockSettings;
}
if (isSpy) {
settings.defaultAnswer(Mockito.CALLS_REAL_METHODS);
}
settings.setMockName(new MockNameImpl(mockName));
settings.setTypeToMock(type);
InternalMockHandler mockHandler = MockHandlerFactory.createMockHandler(settings);
MethodInterceptorFilter filter = new PowerMockMethodInterceptorFilter(mockHandler, settings);
final T mock = new ClassImposterizer(new DefaultInstantiatorProvider().getInstantiator(settings)).imposterise(filter, type);
ClassLoader classLoader = mock.getClass().getClassLoader();
if (classLoader instanceof MockClassLoader) {
MockClassLoader mcl = (MockClassLoader) classLoader;
mcl.cache(mock.getClass());
}
final MockitoMethodInvocationControl invocationControl = new MockitoMethodInvocationControl(filter, isSpy && delegator == null ? new Object() : delegator, mock, methods);
return new MockData<T>(invocationControl, mock);
}
Aggregations