org.mockito.internal.stubbing.OngoingStubbingImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockito-core Show documentation
Show all versions of mockito-core Show documentation
Mockito mock objects library core API and implementation
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.stubbing;
import static org.mockito.internal.exceptions.Reporter.incorrectUseOfApi;
import java.util.List;
import org.mockito.invocation.Invocation;
import org.mockito.quality.Strictness;
import org.mockito.stubbing.Answer;
import org.mockito.stubbing.OngoingStubbing;
public class OngoingStubbingImpl extends BaseStubbing {
private final InvocationContainerImpl invocationContainer;
private Strictness strictness;
public OngoingStubbingImpl(InvocationContainerImpl invocationContainer) {
super(invocationContainer.invokedMock());
this.invocationContainer = invocationContainer;
}
@Override
public OngoingStubbing thenAnswer(Answer answer) {
if (!invocationContainer.hasInvocationForPotentialStubbing()) {
throw incorrectUseOfApi();
}
invocationContainer.addAnswer(answer, strictness);
return new ConsecutiveStubbing(invocationContainer);
}
public List getRegisteredInvocations() {
// TODO interface for tests
return invocationContainer.getInvocations();
}
public void setStrictness(Strictness strictness) {
this.strictness = strictness;
}
}