public <T> T imposterise(final MethodInterceptor interceptor, Class<T> mockedType, Collection<Class> ancillaryTypes) { return imposterise(interceptor, mockedType, ancillaryTypes.toArray(new Class[ancillaryTypes.size()])); }
public <T> T createMock(MockCreationSettings<T> settings, MockHandler handler) { InternalMockHandler mockitoHandler = cast(handler); return ClassImposterizer.INSTANCE.imposterise( new MethodInterceptorFilter(mockitoHandler, settings), settings.getTypeToMock(), settings.getExtraInterfaces()); }
private T getMockWithSynchronizedMethodIntercepting() { SynchronizedMockMethodInterceptorFilter synchronizedMethodInterceptorFilter = createSynchronizedMethodInterceptorFilter(); return ClassImposterizer.INSTANCE.imposterise(synchronizedMethodInterceptorFilter, mockClass, new Class[0]); }
/** * Verifies certain behaviour of all the mocks in the {@link Collection} occurs. Amongst others, the * {@link VerificationMode} can be specified using {@link Mockito#times(int)}, {@link Mockito#never()}, * {@link Mockito#atLeast(int)}, {@link Mockito#atLeastOnce()}, {@link Mockito#atMost(int)}, and * {@link Mockito#only()} (only acts slightly differently). For example: * * <pre class="code"> * <code class="java"> * collectiveVerify(SomeClass.class, collectionOfMocks, times(3)).method("arg"); * collectiveVerify(SomeClass.class, collectionOfMocks, never()).otherMethod("other arg"); * collectiveVerify(SomeClass.class, collectionOfMocks, only()).anotherMethod("another arg"); * </code> * </pre> * * @see #collectiveVerify(Class, Collection) * @see Mockito#verify(Object, VerificationMode) * @param mockClass * @param collection * @param mode * @return Object used for verification of all the mocks in the supplied collection */ public <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) { MethodInterceptor interceptor = new CollectiveVerifyMethodInterceptor(collection, mode); T verifier = ClassImposterizer.INSTANCE.imposterise(interceptor, mockClass); return verifier; }
public Object answer(final InvocationOnMock invocation) throws Throwable { Object defaultReturnValue = delegate.answer(invocation); if (defaultReturnValue != null) { return defaultReturnValue; } Class<?> type = invocation.getMethod().getReturnType(); if (ClassImposterizer.INSTANCE.canImposterise(type)) { return ClassImposterizer.INSTANCE.imposterise(new ThrowingInterceptor(invocation), type); } return null; } }
@Override @SuppressWarnings("unchecked") public <T> T createProxy(Class<?> targetClass, MethodInterceptor interceptor) { // can we subclass the class of the target? if (!ClassImposterizer.INSTANCE.canImposterise(targetClass)) { // delegate return fallbackProxyFactory.<T> createProxy(targetClass, interceptor); } // create proxy T proxy; try { proxy = (T) ClassImposterizer.INSTANCE.imposterise(interceptor, targetClass); } catch (MockitoException e) { // delegate return fallbackProxyFactory.<T> createProxy(targetClass, interceptor); } return proxy; } }
public <T> T createMock(MockCreationSettings<T> settings, MockHandler handler) { InternalMockHandler mockitoHandler = cast(handler); return ClassImposterizer.INSTANCE.imposterise( new MethodInterceptorForGroovyFilter(mockitoHandler, settings), settings.getTypeToMock(), settings.getExtraInterfaces()); }
@SuppressWarnings("unchecked") public <T> T createProxy(Class<?> targetClass, MethodInterceptor interceptor) { // can we subclass the class of the target? if (!ClassImposterizer.INSTANCE.canImposterise(targetClass)) { // delegate return fallbackProxyFactory.<T> createProxy(targetClass, interceptor); } // create proxy T proxy; try { proxy = (T) ClassImposterizer.INSTANCE.imposterise(interceptor, targetClass); } catch (MockitoException e) { // delegate return fallbackProxyFactory.<T> createProxy(targetClass, interceptor); } return proxy; } }
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; }