org.mockito.internal.stubbing
Class StubberImpl

java.lang.Object
  extended by org.mockito.internal.stubbing.StubberImpl
All Implemented Interfaces:
Stubber

public class StubberImpl
extends java.lang.Object
implements Stubber


Constructor Summary
StubberImpl()
           
 
Method Summary
 Stubber doAnswer(Answer answer)
          Use it for stubbing consecutive calls in Mockito.doAnswer(Answer) style:

   doAnswer(answerOne).
 Stubber doCallRealMethod()
          Use it for stubbing consecutive calls in Mockito.doCallRealMethod() style.
 Stubber doNothing()
          Use it for stubbing consecutive calls in Mockito.doNothing() style:

   doNothing().
 Stubber doReturn(java.lang.Object toBeReturned)
          Use it for stubbing consecutive calls in Mockito.doReturn(Object) style.
 Stubber doThrow(java.lang.Class<? extends java.lang.Throwable> toBeThrown)
          Use it for stubbing consecutive calls in Mockito.doThrow(Class) style:

   doThrow(RuntimeException.class).
 Stubber doThrow(java.lang.Throwable toBeThrown)
          Use it for stubbing consecutive calls in Mockito.doThrow(Throwable) style:

   doThrow(new RuntimeException("one")).
<T> T
when(T mock)
          Allows to choose a method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StubberImpl

public StubberImpl()
Method Detail

when

public <T> T when(T mock)
Description copied from 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:

Mockito.doThrow(Throwable)

Mockito.doAnswer(Answer)

Mockito.doNothing()

Mockito.doReturn(Object)

See examples in javadoc for Mockito

Specified by:
when in interface Stubber
Parameters:
mock - The mock
Returns:
select method for stubbing

doReturn

public Stubber doReturn(java.lang.Object toBeReturned)
Description copied from interface: Stubber
Use it for stubbing consecutive calls in Mockito.doReturn(Object) style.

See javadoc for Mockito.doReturn(Object)

Specified by:
doReturn in interface Stubber
Parameters:
toBeReturned - to be returned when the stubbed method is called
Returns:
stubber - to select a method for stubbing

doThrow

public Stubber doThrow(java.lang.Throwable toBeThrown)
Description copied from interface: Stubber
Use it for stubbing consecutive calls in Mockito.doThrow(Throwable) style:

   doThrow(new RuntimeException("one")).
   doThrow(new RuntimeException("two"))
   .when(mock).someVoidMethod();
 
See javadoc for Mockito.doThrow(Throwable)

Specified by:
doThrow in interface Stubber
Parameters:
toBeThrown - to be thrown when the stubbed method is called
Returns:
stubber - to select a method for stubbing

doThrow

public Stubber doThrow(java.lang.Class<? extends java.lang.Throwable> toBeThrown)
Description copied from interface: Stubber
Use it for stubbing consecutive calls in Mockito.doThrow(Class) style:

   doThrow(RuntimeException.class).
   doThrow(IllegalArgumentException.class)
   .when(mock).someVoidMethod();
 
See javadoc for Mockito.doThrow(Class)

Specified by:
doThrow in interface Stubber
Parameters:
toBeThrown - exception class to be thrown when the stubbed method is called
Returns:
stubber - to select a method for stubbing

doNothing

public Stubber doNothing()
Description copied from interface: Stubber
Use it for stubbing consecutive calls in Mockito.doNothing() style:

   doNothing().
   doThrow(new RuntimeException("two"))
   .when(mock).someVoidMethod();
 
See javadoc for Mockito.doNothing()

Specified by:
doNothing in interface Stubber
Returns:
stubber - to select a method for stubbing

doAnswer

public Stubber doAnswer(Answer answer)
Description copied from interface: Stubber
Use it for stubbing consecutive calls in Mockito.doAnswer(Answer) style:

   doAnswer(answerOne).
   doAnswer(answerTwo)
   .when(mock).someVoidMethod();
 
See javadoc for Mockito.doAnswer(Answer)

Specified by:
doAnswer in interface Stubber
Parameters:
answer - to answer when the stubbed method is called
Returns:
stubber - to select a method for stubbing

doCallRealMethod

public Stubber doCallRealMethod()
Description copied from interface: Stubber
Use it for stubbing consecutive calls in Mockito.doCallRealMethod() style.

See javadoc for Mockito.doCallRealMethod()

Specified by:
doCallRealMethod in interface Stubber
Returns:
stubber - to select a method for stubbing