Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.mockito.internal.stubbing
Class ConsecutiveStubbing<T>

    java.lang.Object
      org.mockito.internal.stubbing.BaseStubbing<T>
          org.mockito.internal.stubbing.ConsecutiveStubbing<T>

All Implemented Interfaces:
  IOngoingStubbing, DeprecatedOngoingStubbing<T>, OngoingStubbing<T>

    public class ConsecutiveStubbing<T>

extends BaseStubbing<T>

Constructor Summary
`ConsecutiveStubbing(InvocationContainerImpl invocationContainerImpl)`

Method Summary
`
`<M> M`
` | `getMock()` Returns the mock that was used for this stub.
`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

### ConsecutiveStubbing

    public ConsecutiveStubbing(InvocationContainerImpl invocationContainerImpl)

Method Detail

### thenAnswer

    public OngoingStubbing<T> thenAnswer(Answer<?> answer)

  Description copied from interface: `OngoingStubbing`
  Sets a generic Answer for the method. E.g:

       when(mock.someMethod(10)).thenAnswer(new Answer<Integer>() {
           public Integer answer(InvocationOnMock invocation) throws Throwable {
               return (Integer) invocation.getArguments()[0];
           }
       }

  Parameters:
    `answer` - the custom answer to execute.
  Returns:
    iOngoingStubbing object that allows stubbing consecutive calls

### then

    public OngoingStubbing<T> then(Answer<?> answer)

  Description copied from interface: `OngoingStubbing`
  Sets a generic Answer for the method. This method is an alias of `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());

  Parameters:
    `answer` - the custom answer to execute.
  Returns:
    iOngoingStubbing object that allows stubbing consecutive calls
  See Also:
    `OngoingStubbing.thenAnswer(Answer)`

### toAnswer

    public DeprecatedOngoingStubbing<T> toAnswer(Answer<?> answer)

  Description copied from interface: `DeprecatedOngoingStubbing`
  Set a generic Answer for the stubbed method. E.g:

       stub(mock.someMethod(10)).toAnswer(new Answer<Integer>() {
           public Integer answer(InvocationOnMock invocation) throws Throwable {
               return (Integer) invocation.getArguments()[0];
           }
       }

  Parameters:
    `answer` - the custom answer to execute.
  Returns:
    iOngoingStubbing object that allows stubbing consecutive calls

### getMock

    public <M> M getMock()

  Description copied from interface: `OngoingStubbing`
  Returns the mock that was used for this stub.

  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... {}

  Type Parameters:
    `M` - The mock type given by the variable type.
  Returns:
    Mock used in this ongoing stubbing.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD