@NonInstantiable public final class MoreAnswers extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> org.mockito.stubbing.Answer<T> |
returnArgumentAtIndex(int index)
An answer that returns one of the parameters as the return value.
|
static <T> org.mockito.stubbing.Answer<T> |
returnFirst()
For example:
|
public static <T> org.mockito.stubbing.Answer<T> returnFirst()
when(object.call("firstArg", 3)).then(returnFirst());Will return the"firstArg"string when it is called.
T - returnArgumentAtIndex(int)public static <T> org.mockito.stubbing.Answer<T> returnArgumentAtIndex(int index)
Example:
when(someMock.call(anyString(), anyString()).then(returnArgumentAtIndex(1));
String result = someMock.call("arg1", "arg2");
assertThat(result, is("arg2"));
T - index - zero-based index which determines which parameter to return as an answer.returnFirst()Copyright © 2015–2018 RedRoma, Inc.. All rights reserved.