Package org.mockito.internal.stubbing

Source Code of org.mockito.internal.stubbing.VoidMethodStubbableImpl

/*
* 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<T> implements VoidMethodStubbable<T> {
    private final T mock;
    private final InvocationContainerImpl invocationContainerImpl;

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

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

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

    public VoidMethodStubbable<T> toAnswer(Answer<?> answer) {
        invocationContainerImpl.addAnswerForVoidMethod(answer);
        return this;
    }

    public T on() {
        return mock;
    }
}
TOP

Related Classes of org.mockito.internal.stubbing.VoidMethodStubbableImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.