All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.mockito.internal.stubbing.OngoingStubbingImpl Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package com.fitbur.mockito.internal.stubbing;

import com.fitbur.mockito.exceptions.Reporter;
import com.fitbur.mockito.invocation.Invocation;
import com.fitbur.mockito.stubbing.Answer;
import com.fitbur.mockito.stubbing.OngoingStubbing;

import static com.fitbur.mockito.exceptions.Reporter.incorrectUseOfApi;

import java.util.List;

public class OngoingStubbingImpl extends BaseStubbing {
    
    private final InvocationContainerImpl invocationContainerImpl;

    public OngoingStubbingImpl(InvocationContainerImpl invocationContainerImpl) {
        this.invocationContainerImpl = invocationContainerImpl;
    }

    public OngoingStubbing thenAnswer(Answer answer) {
        if(!invocationContainerImpl.hasInvocationForPotentialStubbing()) {
            throw incorrectUseOfApi();
        }

        invocationContainerImpl.addAnswer(answer);
        return new ConsecutiveStubbing(invocationContainerImpl);
    }

    public OngoingStubbing then(Answer answer) {
        return thenAnswer(answer);
    }

    public List getRegisteredInvocations() {
        //TODO interface for tests
        return invocationContainerImpl.getInvocations();
    }

    @SuppressWarnings("unchecked")
    public  M getMock() {
        return (M) invocationContainerImpl.invokedMock();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy