org.mockito.stubbing.Stubber Maven / Gradle / Ivy
Show all versions of mockito-core Show documentation
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.stubbing;
import org.mockito.CheckReturnValue;
import org.mockito.Mockito;
import org.mockito.NotExtensible;
/**
* 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}
*/
@CheckReturnValue
@SuppressWarnings("unchecked")
@NotExtensible
public interface Stubber extends BaseStubber {
/**
* 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 The mock
* @return select method for stubbing
*/
T when(T mock);
}