public <T> T createMock(Class<T> classToMock, MockSettingsImpl settings) {
creationValidator.validateType(classToMock);
creationValidator.validateExtraInterfaces(classToMock, settings.getExtraInterfaces());
creationValidator.validateMockedType(classToMock, settings.getSpiedInstance());
settings.initiateMockName(classToMock);
MockHandler<T> mockHandler = new MockHandler<T>(settings);
InvocationNotifierHandler<T> invocationNotifierHandler = new InvocationNotifierHandler<T>(mockHandler, settings);
MethodInterceptorFilter filter = new MethodInterceptorFilter(invocationNotifierHandler, settings);
Class<?>[] interfaces = settings.getExtraInterfaces();
Class<?>[] ancillaryTypes;
if (settings.isSerializable()) {
ancillaryTypes = interfaces == null ? new Class<?>[] {Serializable.class} : new ArrayUtils().concat(interfaces, Serializable.class);
} else {
ancillaryTypes = interfaces == null ? new Class<?>[0] : interfaces;
}
Object spiedInstance = settings.getSpiedInstance();
T mock = ClassImposterizer.INSTANCE.imposterise(filter, classToMock, ancillaryTypes);
if (spiedInstance != null) {
new LenientCopyTool().copyToMock(spiedInstance, mock);
}
return mock;
}