org.mockito.stubbing.Stubber Maven / Gradle / Ivy
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.stubbing;
import org.mockito.Mockito;
/**
* Allows to choose a method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style
*
* Example:
*
* doThrow(new RuntimeException()).when(mockedList).clear();
*
* //following throws RuntimeException:
* mockedList.clear();
*
*
* Also useful when stubbing consecutive calls:
*
*
* doThrow(new RuntimeException("one")).
* doThrow(new RuntimeException("two"))
* .when(mock).someVoidMethod();
*
*
* Read more about those methods:
*
* {@link Mockito#doThrow(Throwable)}
*
* {@link Mockito#doAnswer(Answer)}
*
* {@link Mockito#doNothing()}
*
* {@link Mockito#doReturn(Object)}
*
*
* See examples in javadoc for {@link Mockito}
*/
@SuppressWarnings("unchecked")
public interface Stubber {
/**
* Allows to choose a method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style
*
* Example:
*
* doThrow(new RuntimeException())
* .when(mockedList).clear();
*
* //following throws RuntimeException:
* mockedList.clear();
*
*
* Read more about those methods:
*
* {@link Mockito#doThrow(Throwable)}
*
* {@link Mockito#doAnswer(Answer)}
*
* {@link Mockito#doNothing()}
*
* {@link Mockito#doReturn(Object)}
*
*
* See examples in javadoc for {@link Mockito}
*
* @param mock
* @return select method for stubbing
*/
T when(T mock);
/**
* Use it for stubbing consecutive calls in {@link Mockito#doThrow(Throwable)} style:
*
* doThrow(new RuntimeException("one")).
* doThrow(new RuntimeException("two"))
* .when(mock).someVoidMethod();
*
* See javadoc for {@link Mockito#doThrow(Throwable)}
*
* @param toBeThrown to be thrown when the stubbed method is called
* @return stubber - to select a method for stubbing
*/
Stubber doThrow(Throwable toBeThrown);
/**
* Use it for stubbing consecutive calls in {@link Mockito#doAnswer(Answer)} style:
*
* doAnswer(answerOne).
* doAnswer(answerTwo)
* .when(mock).someVoidMethod();
*
* See javadoc for {@link Mockito#doAnswer(Answer)}
*
* @param answer to answer when the stubbed method is called
* @return stubber - to select a method for stubbing
*/
Stubber doAnswer(Answer answer);
/**
* Use it for stubbing consecutive calls in {@link Mockito#doNothing()} style:
*
* doNothing().
* doThrow(new RuntimeException("two"))
* .when(mock).someVoidMethod();
*
* See javadoc for {@link Mockito#doNothing()}
*
* @return stubber - to select a method for stubbing
*/
Stubber doNothing();
/**
* Use it for stubbing consecutive calls in {@link Mockito#doReturn(Object)} style.
*
* See javadoc for {@link Mockito#doReturn(Object)}
*
* @param toBeReturned to be returned when the stubbed method is called
* @return stubber - to select a method for stubbing
*/
Stubber doReturn(Object toBeReturned);
}