private <T> void prepareForStubbing(T mock) { MockitoMethodInvocationControl invocationControl = (MockitoMethodInvocationControl) MockRepository.getInstanceMethodInvocationControl(mock); addAnswersForStubbing(invocationControl); }
public static void verifyNoMoreInteractions(Object... objects) { for (Object mock : objects) { if (mock instanceof Class<?>) { verifyNoMoreInteractions((Class<?>) mock); } else { MockitoMethodInvocationControl invocationControl = (MockitoMethodInvocationControl) MockRepository .getInstanceMethodInvocationControl(mock); if (invocationControl != null) { invocationControl.verifyNoMoreInteractions(); } else { /* * Delegate to Mockito if we have no handler registered for * this object. */ Mockito.verifyNoMoreInteractions(mock); } } } }
/** * Supports PowerMockito mocks. If {@code mock} is not a PowerMockito * mock it will delegate to Mockito. * * @see Stubber#when(Object) */ @Override public <T> T when(T instanceMock) { MockitoMethodInvocationControl invocationControl = (MockitoMethodInvocationControl) MockRepository .getInstanceMethodInvocationControl(instanceMock); final T returnValue; if (invocationControl == null) { returnValue = super.when(instanceMock); } else { addAnswersForStubbing(invocationControl); returnValue = instanceMock; } return returnValue; }
private Object performIntercept(MethodInterceptorFilter invocationHandler, final Object interceptionObject, final Method method, Object[] arguments) throws Throwable { MockHandler mockHandler = invocationHandler.getHandler(); final CleanTraceRealMethod cglibProxyRealMethod = new CleanTraceRealMethod(new MockedRealMethod(method, interceptionObject)); Invocation invocation = new InvocationImpl( interceptionObject, new DelegatingMethod(method), arguments, SequenceNumber.next(), cglibProxyRealMethod) { private static final long serialVersionUID = -3679957412502758558L; @Override public String toString() { return new ToStringGenerator().generate(getMock(), getMethod(), getArguments()); } }; try { return replaceMatchersBinderIfNeeded(mockHandler).handle(invocation); } catch (NotAMockException e) { if(invocation.getMock().getClass().getName().startsWith("java.") && MockRepository.getInstanceMethodInvocationControl(invocation.getMock()) != null) { return invocation.callRealMethod(); } else { throw e; } } catch (MockitoAssertionError e) { InvocationControlAssertionError.updateErrorMessageForMethodInvocation(e); throw e; } }
@Override public <T> T when(final T instanceMock) { final MockitoMethodInvocationControl invocationControl = (MockitoMethodInvocationControl) MockRepository.getInstanceMethodInvocationControl(instanceMock); final T returnValue; if (invocationControl == null) { returnValue = stubber.when(instanceMock); } else { final Object mock = invocationControl.getMockHandlerAdaptor().getMock(); stubber.when(mock); returnValue = instanceMock; } return returnValue; }
private Object getRealMock(final Object mock) { final MockitoMethodInvocationControl invocationControl = (MockitoMethodInvocationControl) MockRepository.getInstanceMethodInvocationControl(mock); final Object realMock; if (invocationControl == null){ realMock = mock; }else{ realMock = invocationControl.getMockHandlerAdaptor().getMock(); } return realMock; }
public static void verifyNoMoreInteractions(Object... objects) { for (Object mock : objects) { if (mock instanceof Class<?>) { verifyNoMoreInteractions((Class<?>) mock); } else { MockitoMethodInvocationControl invocationControl = (MockitoMethodInvocationControl) MockRepository .getInstanceMethodInvocationControl(mock); if (invocationControl != null) { invocationControl.verifyNoMoreInteractions(); } else { /* * Delegate to Mockito if we have no handler registered for * this object. */ Mockito.verifyNoMoreInteractions(mock); } } } }
private void init() { if (object instanceof Class<?>) { objectType = (Class<?>) object; methodInvocationControl = MockRepository.getStaticMethodInvocationControl(objectType); } else { final Class<?> type = object.getClass(); UnproxiedType unproxiedType = WhiteboxImpl.getUnproxiedType(type); objectType = unproxiedType.getOriginalType(); methodInvocationControl = MockRepository.getInstanceMethodInvocationControl(object); } method = findMethodToInvoke(methodName, sig, objectType); }
Object performIntercept(final Object mock, final Method method, Object[] arguments) throws Throwable { Invocation invocation = createInvocation(mock, method, arguments); try { return getMockHandler().handle(invocation); } catch (NotAMockException e) { if (invocation.getMock() .getClass() .getName() .startsWith("java.") && MockRepository.getInstanceMethodInvocationControl(invocation.getMock()) != null) { return invocation.callRealMethod(); } else { throw e; } } catch (MockitoAssertionError e) { InvocationControlAssertionError.updateErrorMessageForMethodInvocation(e); throw e; } }
public Object invoke(Class<?> type, Object[] args, Class<?>[] sig) throws Exception { Constructor<?> constructor = WhiteboxImpl.getConstructor(type, sig); if (constructor.isVarArgs()) { /* * Get the first argument because this contains the actual varargs * arguments. */ args = (Object[]) args[0]; } try { final MockType mockType = ((EasyMockMethodInvocationControl<?>) MockRepository.getInstanceMethodInvocationControl(substitute)) .getMockType(); Object result = substitute.performSubstitutionLogic(args); if (result == null) { if (mockType == MockType.NICE) { result = EasyMock.createNiceMock(subsitutionType); } else { throw new IllegalStateException("Must replay class " + type.getName() + " to get configured expectation."); } } return result; } catch (AssertionError e) { NewInvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(e, type); } // Won't happen return null; }
verifyClass((Class<?>) mock); } else { MethodInvocationControl invocationControl = MockRepository.getInstanceMethodInvocationControl(mock); if (invocationControl != null) { invocationControl.verify();
reset((Class<?>) mock); } else { MethodInvocationControl invocationControl = MockRepository.getInstanceMethodInvocationControl(mock); if (invocationControl != null) { invocationControl.reset();
replay((Class<?>) mock); } else { MethodInvocationControl invocationControl = MockRepository.getInstanceMethodInvocationControl(mock); if (invocationControl != null) { invocationControl.replay();