Search in sources :

Example 6 with MockingProgress

use of org.mockito.internal.progress.MockingProgress 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 7 with MockingProgress

use of org.mockito.internal.progress.MockingProgress in project mockito by mockito.

the class MockitoCore method when.

public <T> OngoingStubbing<T> when(T methodCall) {
    MockingProgress mockingProgress = mockingProgress();
    mockingProgress.stubbingStarted();
    @SuppressWarnings("unchecked") OngoingStubbing<T> stubbing = (OngoingStubbing<T>) mockingProgress.pullOngoingStubbing();
    if (stubbing == null) {
        mockingProgress.reset();
        throw missingMethodInvocation();
    }
    return stubbing;
}
Also used : OngoingStubbing(org.mockito.stubbing.OngoingStubbing) MockingProgress(org.mockito.internal.progress.MockingProgress)

Example 8 with MockingProgress

use of org.mockito.internal.progress.MockingProgress in project mockito by mockito.

the class MockitoCore method clearInvocations.

public <T> void clearInvocations(T... mocks) {
    MockingProgress mockingProgress = mockingProgress();
    mockingProgress.validateState();
    mockingProgress.reset();
    mockingProgress.resetOngoingStubbing();
    for (T m : mocks) {
        getInvocationContainer(m).clearInvocations();
    }
}
Also used : MockingProgress(org.mockito.internal.progress.MockingProgress)

Example 9 with MockingProgress

use of org.mockito.internal.progress.MockingProgress in project mockito by mockito.

the class MockedStaticImpl method clearInvocations.

@Override
public void clearInvocations() {
    assertNotClosed();
    MockingProgress mockingProgress = mockingProgress();
    mockingProgress.validateState();
    mockingProgress.reset();
    mockingProgress.resetOngoingStubbing();
    getInvocationContainer(control.getType()).clearInvocations();
}
Also used : MockingProgress(org.mockito.internal.progress.MockingProgress)

Example 10 with MockingProgress

use of org.mockito.internal.progress.MockingProgress 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)

Aggregations

MockingProgress (org.mockito.internal.progress.MockingProgress)10 MockingDetails (org.mockito.MockingDetails)2 MockitoException (org.mockito.exceptions.base.MockitoException)2 StubberImpl (org.mockito.internal.stubbing.StubberImpl)2 MockAwareVerificationMode (org.mockito.internal.verification.MockAwareVerificationMode)2 MockHandler (org.mockito.invocation.MockHandler)2 OngoingStubbing (org.mockito.stubbing.OngoingStubbing)2 VerificationMode (org.mockito.verification.VerificationMode)2 MockitoAssertionError (org.mockito.exceptions.base.MockitoAssertionError)1 DefaultMockingDetails (org.mockito.internal.util.DefaultMockingDetails)1 MockUtil.getMockHandler (org.mockito.internal.util.MockUtil.getMockHandler)1