Search in sources :

Example 21 with VerificationMode

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));
}
Also used : Method(java.lang.reflect.Method) VerificationMode(org.mockito.verification.VerificationMode) Test(org.junit.Test)

Example 22 with VerificationMode

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;
}
Also used : MockAwareVerificationMode(org.mockito.internal.verification.MockAwareVerificationMode) DefaultMockingDetails(org.mockito.internal.util.DefaultMockingDetails) MockingDetails(org.mockito.MockingDetails) MockUtil.getMockHandler(org.mockito.internal.util.MockUtil.getMockHandler) MockHandler(org.mockito.invocation.MockHandler) MockingProgress(org.mockito.internal.progress.MockingProgress) MockAwareVerificationMode(org.mockito.internal.verification.MockAwareVerificationMode) VerificationMode(org.mockito.verification.VerificationMode)

Example 23 with VerificationMode

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);
    }
}
Also used : MockAwareVerificationMode(org.mockito.internal.verification.MockAwareVerificationMode) MockitoAssertionError(org.mockito.exceptions.base.MockitoAssertionError) MockitoException(org.mockito.exceptions.base.MockitoException) MockingDetails(org.mockito.MockingDetails) MockHandler(org.mockito.invocation.MockHandler) MockingProgress(org.mockito.internal.progress.MockingProgress) MockAwareVerificationMode(org.mockito.internal.verification.MockAwareVerificationMode) VerificationMode(org.mockito.verification.VerificationMode)

Example 24 with VerificationMode

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]");
}
Also used : VerificationMode(org.mockito.verification.VerificationMode) DummyVerificationMode(org.mockito.internal.verification.DummyVerificationMode) Test(org.junit.Test)

Example 25 with VerificationMode

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]");
}
Also used : VerificationMode(org.mockito.verification.VerificationMode) DummyVerificationMode(org.mockito.internal.verification.DummyVerificationMode) Test(org.junit.Test)

Aggregations

VerificationMode (org.mockito.verification.VerificationMode)31 Test (org.junit.Test)18 DummyVerificationMode (org.mockito.internal.verification.DummyVerificationMode)5 MockAwareVerificationMode (org.mockito.internal.verification.MockAwareVerificationMode)3 SnapshotPolicyVO (com.cloud.storage.SnapshotPolicyVO)2 StoragePoolType (com.cloud.storage.Storage.StoragePoolType)2 IntervalType (com.cloud.utils.DateUtil.IntervalType)2 Method (java.lang.reflect.Method)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 AcknowledgeCheckpoint (org.apache.flink.runtime.messages.checkpoint.AcknowledgeCheckpoint)2 DeclineCheckpoint (org.apache.flink.runtime.messages.checkpoint.DeclineCheckpoint)2 OperatorStreamStateHandle (org.apache.flink.runtime.state.OperatorStreamStateHandle)2 PlaceholderStreamStateHandle (org.apache.flink.runtime.state.PlaceholderStreamStateHandle)2 StateHandleID (org.apache.flink.runtime.state.StateHandleID)2 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)2 TestingStreamStateHandle (org.apache.flink.runtime.state.TestingStreamStateHandle)2 ByteStreamStateHandle (org.apache.flink.runtime.state.memory.ByteStreamStateHandle)2