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

org.mockito.internal.stubbing.VoidMethodStubbableImpl Maven / Gradle / Ivy

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

import org.mockito.internal.stubbing.answers.DoesNothing;
import org.mockito.internal.stubbing.answers.ThrowsException;
import org.mockito.stubbing.Answer;
import org.mockito.stubbing.VoidMethodStubbable;

public class VoidMethodStubbableImpl implements VoidMethodStubbable {
    private final T mock;
    private InvocationContainerImpl invocationContainerImpl;

    public VoidMethodStubbableImpl(T mock, InvocationContainerImpl invocationContainerImpl) {
        this.mock = mock;
        this.invocationContainerImpl = invocationContainerImpl;
    }

    public VoidMethodStubbable toThrow(Throwable throwable) {
        invocationContainerImpl.addAnswerForVoidMethod(new ThrowsException(throwable));
        return this;
    }

    public VoidMethodStubbable toReturn() {
        invocationContainerImpl.addAnswerForVoidMethod(new DoesNothing());
        return this;
    }

    public VoidMethodStubbable toAnswer(Answer answer) {
        invocationContainerImpl.addAnswerForVoidMethod(answer);
        return this;
    }

    public T on() {
        return mock;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy