use of org.mockito.verification.VerificationMode in project mockito by mockito.
the class VerificationListenerCallBackTest method should_call_all_listeners_on_verify.
@Test
public void should_call_all_listeners_on_verify() throws NoSuchMethodException {
// given
RememberingListener listener1 = new RememberingListener();
RememberingListener2 listener2 = new RememberingListener2();
Mockito.framework().addListener(listener1).addListener(listener2);
Method invocationWanted = Foo.class.getDeclaredMethod("doSomething", String.class);
Foo foo = mock(Foo.class);
// when
VerificationMode never = never();
verify(foo, never).doSomething("");
// then
assertThat(listener1).is(notifiedFor(foo, never, invocationWanted));
assertThat(listener2).is(notifiedFor(foo, never, invocationWanted));
}
use of org.mockito.verification.VerificationMode in project mockito by mockito.
the class MockitoCore method verify.
public <T> T verify(T mock, VerificationMode mode) {
if (mock == null) {
throw nullPassedToVerify();
}
MockingDetails mockingDetails = mockingDetails(mock);
if (!mockingDetails.isMock()) {
throw notAMockPassedToVerify(mock.getClass());
}
assertNotStubOnlyMock(mock);
MockHandler handler = mockingDetails.getMockHandler();
mock = (T) VerificationStartedNotifier.notifyVerificationStarted(handler.getMockSettings().getVerificationStartedListeners(), mockingDetails);
MockingProgress mockingProgress = mockingProgress();
VerificationMode actualMode = mockingProgress.maybeVerifyLazily(mode);
mockingProgress.verificationStarted(new MockAwareVerificationMode(mock, actualMode, mockingProgress.verificationListeners()));
return mock;
}
use of org.mockito.verification.VerificationMode in project mockito by mockito.
the class MockedStaticImpl method verify.
@Override
public void verify(Verification verification, VerificationMode mode) {
assertNotClosed();
MockingDetails mockingDetails = Mockito.mockingDetails(control.getType());
MockHandler handler = mockingDetails.getMockHandler();
VerificationStartedNotifier.notifyVerificationStarted(handler.getMockSettings().getVerificationStartedListeners(), mockingDetails);
MockingProgress mockingProgress = mockingProgress();
VerificationMode actualMode = mockingProgress.maybeVerifyLazily(mode);
mockingProgress.verificationStarted(new MockAwareVerificationMode(control.getType(), actualMode, mockingProgress.verificationListeners()));
try {
verification.apply();
} catch (MockitoException | MockitoAssertionError e) {
throw e;
} catch (Throwable t) {
throw new MockitoException(join("An unexpected error occurred while verifying a static stub", "", "To correctly verify a stub, invoke a single static method of " + control.getType().getName() + " in the provided lambda.", "For example, if a method 'sample' was defined, provide a lambda or anonymous class containing the code", "", "() -> " + control.getType().getSimpleName() + ".sample()", "or", control.getType().getSimpleName() + "::sample"), t);
}
}
use of org.mockito.verification.VerificationMode in project mockito by mockito.
the class VerificationWithTimeoutTest method should_return_formatted_output_from_toString_when_created_with_factory_method.
@Test
public void should_return_formatted_output_from_toString_when_created_with_factory_method() {
VerificationMode timeout = timeout(7);
assertThat(timeout).hasToString("Wanted after at most 7 ms: [Wanted invocations count: 1]");
}
use of org.mockito.verification.VerificationMode in project mockito by mockito.
the class VerificationWithAfterTest method should_return_formatted_output_from_toString_when_chaining_other_verification_mode.
@Test
public void should_return_formatted_output_from_toString_when_chaining_other_verification_mode() {
VerificationMode afterAndOnly = after(5).only();
assertThat(afterAndOnly).hasToString("Wanted after 5 ms: [Wanted invocations count: 1 and no other method invoked]");
}
Aggregations