Search in sources :

Example 1 with ValidableAnswer

use of org.mockito.stubbing.ValidableAnswer in project mockito by mockito.

the class InvocationContainerImpl method addAnswer.

/**
 * Adds new stubbed answer and returns the invocation matcher the answer was added to.
 */
public StubbedInvocationMatcher addAnswer(Answer answer, boolean isConsecutive, Strictness stubbingStrictness) {
    Invocation invocation = invocationForStubbing.getInvocation();
    mockingProgress().stubbingCompleted();
    if (answer instanceof ValidableAnswer) {
        ((ValidableAnswer) answer).validateFor(invocation);
    }
    synchronized (stubbed) {
        if (isConsecutive) {
            stubbed.getFirst().addAnswer(answer);
        } else {
            Strictness effectiveStrictness = stubbingStrictness != null ? stubbingStrictness : this.mockStrictness;
            stubbed.addFirst(new StubbedInvocationMatcher(answer, invocationForStubbing, effectiveStrictness));
        }
        return stubbed.getFirst();
    }
}
Also used : Invocation(org.mockito.invocation.Invocation) MatchableInvocation(org.mockito.invocation.MatchableInvocation) SingleRegisteredInvocation(org.mockito.internal.verification.SingleRegisteredInvocation) ValidableAnswer(org.mockito.stubbing.ValidableAnswer) Strictness(org.mockito.quality.Strictness)

Example 2 with ValidableAnswer

use of org.mockito.stubbing.ValidableAnswer in project mockito by mockito.

the class InvocationContainerImpl method addAnswer.

/**
     * Adds new stubbed answer and returns the invocation matcher the answer was added to.
     */
public StubbedInvocationMatcher addAnswer(Answer answer, boolean isConsecutive) {
    Invocation invocation = invocationForStubbing.getInvocation();
    mockingProgress().stubbingCompleted();
    if (answer instanceof ValidableAnswer) {
        ((ValidableAnswer) answer).validateFor(invocation);
    }
    synchronized (stubbed) {
        if (isConsecutive) {
            stubbed.getFirst().addAnswer(answer);
        } else {
            stubbed.addFirst(new StubbedInvocationMatcher(invocationForStubbing, answer));
        }
        return stubbed.getFirst();
    }
}
Also used : Invocation(org.mockito.invocation.Invocation) SingleRegisteredInvocation(org.mockito.internal.verification.SingleRegisteredInvocation) ValidableAnswer(org.mockito.stubbing.ValidableAnswer)

Aggregations

SingleRegisteredInvocation (org.mockito.internal.verification.SingleRegisteredInvocation)2 Invocation (org.mockito.invocation.Invocation)2 ValidableAnswer (org.mockito.stubbing.ValidableAnswer)2 MatchableInvocation (org.mockito.invocation.MatchableInvocation)1 Strictness (org.mockito.quality.Strictness)1