|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.mockito.internal.stubbing.BaseStubbing<T> org.mockito.internal.stubbing.OngoingStubbingImpl<T>
public class OngoingStubbingImpl<T>
Constructor Summary | |
---|---|
OngoingStubbingImpl(InvocationContainerImpl invocationContainerImpl)
|
Method Summary | ||
---|---|---|
|
getMock()
Returns the mock that was used for this stub. |
|
java.util.List<Invocation> |
getRegisteredInvocations()
|
|
OngoingStubbing<T> |
then(Answer<?> answer)
Sets a generic Answer for the method. |
|
OngoingStubbing<T> |
thenAnswer(Answer<?> answer)
Sets a generic Answer for the method. |
|
DeprecatedOngoingStubbing<T> |
toAnswer(Answer<?> answer)
Set a generic Answer for the stubbed method. |
Methods inherited from class org.mockito.internal.stubbing.BaseStubbing |
---|
thenCallRealMethod, thenReturn, thenReturn, thenThrow, thenThrow, toReturn, toThrow |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public OngoingStubbingImpl(InvocationContainerImpl invocationContainerImpl)
Method Detail |
---|
public OngoingStubbing<T> thenAnswer(Answer<?> answer)
OngoingStubbing
when(mock.someMethod(10)).thenAnswer(new Answer<Integer>() { public Integer answer(InvocationOnMock invocation) throws Throwable { return (Integer) invocation.getArguments()[0]; } }
answer
- the custom answer to execute.
public OngoingStubbing<T> then(Answer<?> answer)
OngoingStubbing
OngoingStubbing.thenAnswer(Answer)
. This alias allows
more readable tests on occasion, for example:
//using 'then' alias: when(mock.foo()).then(returnCoolValue()); //versus good old 'thenAnswer: when(mock.foo()).thenAnswer(byReturningCoolValue());
answer
- the custom answer to execute.
OngoingStubbing.thenAnswer(Answer)
public DeprecatedOngoingStubbing<T> toAnswer(Answer<?> answer)
DeprecatedOngoingStubbing
stub(mock.someMethod(10)).toAnswer(new Answer<Integer>() { public Integer answer(InvocationOnMock invocation) throws Throwable { return (Integer) invocation.getArguments()[0]; } }
answer
- the custom answer to execute.
public java.util.List<Invocation> getRegisteredInvocations()
public <M> M getMock()
OngoingStubbing
It allows to create a stub in one line of code. This can be helpful to keep test code clean. For example, some boring stub can be created & stubbed at field initialization in a test:
public class CarTest { Car boringStubbedCar = when(mock(Car.class).shiftGear()).thenThrow(EngineNotStarted.class).getMock(); @Test public void should... {}
M
- The mock type given by the variable type.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |