Search in sources :

Example 1 with DynamicProxyMockInterceptorAdapter

use of org.spockframework.mock.runtime.DynamicProxyMockInterceptorAdapter in project spock by spockframework.

the class DynamicProxyMockFactory method createMock.

static Object createMock(Class<?> mockType, List<Class<?>> additionalInterfaces, List<Object> constructorArgs, IProxyBasedMockInterceptor mockInterceptor, ClassLoader classLoader) {
    if (constructorArgs != null) {
        throw new InvalidSpecException("Interface based mocks may not have constructor arguments");
    }
    List<Class<?>> interfaces = new ArrayList<>();
    interfaces.add(mockType);
    interfaces.addAll(additionalInterfaces);
    interfaces.add(ISpockMockObject.class);
    return Proxy.newProxyInstance(classLoader, interfaces.toArray(CLASSES), new DynamicProxyMockInterceptorAdapter(mockInterceptor));
}
Also used : InvalidSpecException(org.spockframework.runtime.InvalidSpecException) ArrayList(java.util.ArrayList) DynamicProxyMockInterceptorAdapter(org.spockframework.mock.runtime.DynamicProxyMockInterceptorAdapter)

Aggregations

ArrayList (java.util.ArrayList)1 DynamicProxyMockInterceptorAdapter (org.spockframework.mock.runtime.DynamicProxyMockInterceptorAdapter)1 InvalidSpecException (org.spockframework.runtime.InvalidSpecException)1