use of org.mockito.internal.verification.VerificationDataImpl in project powermock by powermock.
the class MockitoMethodInvocationControl method verifyNoMoreInteractions.
public void verifyNoMoreInteractions() {
try {
final MockHandler mockHandler = methodInterceptorFilter.getHandler();
if (mockHandler instanceof MockHandler) {
InvocationContainer invocationContainer = Whitebox.invokeMethod(mockHandler, "getInvocationContainer");
VerificationDataImpl data = new VerificationDataImpl(invocationContainer, null);
VerificationModeFactory.noMoreInteractions().verify(data);
} else {
throw new RuntimeException("Cannot perform verifyNoMoreInteractions because of unknown mockhandler type " + mockHandler.getClass());
}
} catch (MockitoAssertionError e) {
InvocationControlAssertionError.updateErrorMessageForVerifyNoMoreInteractions(e);
throw e;
} catch (Exception e) {
throw new RuntimeException("PowerMock internal error", e);
}
}
use of org.mockito.internal.verification.VerificationDataImpl in project mockito by mockito.
the class MockitoCore method verifyNoMoreInteractions.
public void verifyNoMoreInteractions(Object... mocks) {
assertMocksNotEmpty(mocks);
mockingProgress().validateState();
for (Object mock : mocks) {
try {
if (mock == null) {
throw nullPassedToVerifyNoMoreInteractions();
}
InvocationContainerImpl invocations = getInvocationContainer(mock);
assertNotStubOnlyMock(mock);
VerificationDataImpl data = new VerificationDataImpl(invocations, null);
noMoreInteractions().verify(data);
} catch (NotAMockException e) {
throw notAMockPassedToVerifyNoMoreInteractions();
}
}
}
use of org.mockito.internal.verification.VerificationDataImpl in project mockito by mockito.
the class MockHandlerImpl method handle.
@Override
public Object handle(Invocation invocation) throws Throwable {
if (invocationContainer.hasAnswersForStubbing()) {
// stubbing voids with doThrow() or doAnswer() style
InvocationMatcher invocationMatcher = matchersBinder.bindMatchers(mockingProgress().getArgumentMatcherStorage(), invocation);
invocationContainer.setMethodForStubbing(invocationMatcher);
return null;
}
VerificationMode verificationMode = mockingProgress().pullVerificationMode();
InvocationMatcher invocationMatcher = matchersBinder.bindMatchers(mockingProgress().getArgumentMatcherStorage(), invocation);
mockingProgress().validateState();
// if verificationMode is not null then someone is doing verify()
if (verificationMode != null) {
// - see VerifyingWithAnExtraCallToADifferentMockTest (bug 138)
if (MockUtil.areSameMocks(((MockAwareVerificationMode) verificationMode).getMock(), invocation.getMock())) {
VerificationDataImpl data = new VerificationDataImpl(invocationContainer, invocationMatcher);
verificationMode.verify(data);
return null;
} else {
// this means there is an invocation on a different mock. Re-adding verification
// mode
// - see VerifyingWithAnExtraCallToADifferentMockTest (bug 138)
mockingProgress().verificationStarted(verificationMode);
}
}
// prepare invocation for stubbing
invocationContainer.setInvocationForPotentialStubbing(invocationMatcher);
OngoingStubbingImpl<T> ongoingStubbing = new OngoingStubbingImpl<T>(invocationContainer);
mockingProgress().reportOngoingStubbing(ongoingStubbing);
// look for existing answer for this invocation
StubbedInvocationMatcher stubbing = invocationContainer.findAnswerFor(invocation);
// TODO #793 - when completed, we should be able to get rid of the casting below
notifyStubbedAnswerLookup(invocation, stubbing, invocationContainer.getStubbingsAscending(), (CreationSettings) mockSettings);
if (stubbing != null) {
stubbing.captureArgumentsFrom(invocation);
try {
return stubbing.answer(invocation);
} finally {
// Needed so that we correctly isolate stubbings in some scenarios
// see MockitoStubbedCallInAnswerTest or issue #1279
mockingProgress().reportOngoingStubbing(ongoingStubbing);
}
} else {
Object ret = mockSettings.getDefaultAnswer().answer(invocation);
DefaultAnswerValidator.validateReturnValueFor(invocation, ret);
// Mockito uses it to redo setting invocation for potential stubbing in case of partial
// mocks / spies.
// Without it, the real method inside 'when' might have delegated to other self method
// and overwrite the intended stubbed method with a different one.
// This means we would be stubbing a wrong method.
// Typically this would led to runtime exception that validates return type with stubbed
// method signature.
invocationContainer.resetInvocationForPotentialStubbing(invocationMatcher);
return ret;
}
}
use of org.mockito.internal.verification.VerificationDataImpl in project mockito by mockito.
the class MockitoCore method verifyNoInteractions.
public void verifyNoInteractions(Object... mocks) {
assertMocksNotEmpty(mocks);
mockingProgress().validateState();
for (Object mock : mocks) {
try {
if (mock == null) {
throw nullPassedToVerifyNoMoreInteractions();
}
InvocationContainerImpl invocations = getInvocationContainer(mock);
assertNotStubOnlyMock(mock);
VerificationDataImpl data = new VerificationDataImpl(invocations, null);
noInteractions().verify(data);
} catch (NotAMockException e) {
throw notAMockPassedToVerifyNoMoreInteractions();
}
}
}
use of org.mockito.internal.verification.VerificationDataImpl in project mockito by mockito.
the class MockedStaticImpl method verifyNoInteractions.
@Override
public void verifyNoInteractions() {
assertNotClosed();
mockingProgress().validateState();
InvocationContainerImpl invocations = getInvocationContainer(control.getType());
VerificationDataImpl data = new VerificationDataImpl(invocations, null);
noInteractions().verify(data);
}
Aggregations