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 MockitoStubber mockitoStubber;

    public VoidMethodStubbableImpl(T mock, MockitoStubber mockitoStubber) {
        this.mock = mock;
        this.mockitoStubber = mockitoStubber;
    }

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

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

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

    public T on() {
        return mock;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy