Package org.mockito.internal.stubbing
Class StubberImpl
- java.lang.Object
-
- org.mockito.internal.stubbing.StubberImpl
-
- All Implemented Interfaces:
BaseStubber,Stubber
public class StubberImpl extends java.lang.Object implements Stubber
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Answer<?>>answersprivate Strictnessstrictness
-
Constructor Summary
Constructors Constructor Description StubberImpl(Strictness strictness)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StubberdoAnswer(Answer answer)Use it for stubbing consecutive calls inMockito.doAnswer(Answer)style:StubberdoCallRealMethod()Use it for stubbing consecutive calls inMockito.doCallRealMethod()style.StubberdoNothing()Use it for stubbing consecutive calls inMockito.doNothing()style:StubberdoReturn(java.lang.Object toBeReturned)Use it for stubbing consecutive calls inMockito.doReturn(Object)style.StubberdoReturn(java.lang.Object toBeReturned, java.lang.Object... nextToBeReturned)Use it for stubbing consecutive calls inMockito.doReturn(Object)style.private StubberImpldoReturnValues(java.lang.Object... toBeReturned)StubberdoThrow(java.lang.Class<? extends java.lang.Throwable> toBeThrown)Use it for stubbing consecutive calls inMockito.doThrow(Class)style:StubberdoThrow(java.lang.Class<? extends java.lang.Throwable> toBeThrown, java.lang.Class<? extends java.lang.Throwable>... nextToBeThrown)Use it for stubbing consecutive calls inMockito.doThrow(Class)style:StubberdoThrow(java.lang.Throwable... toBeThrown)Use it for stubbing consecutive calls inMockito.doThrow(Throwable[])style:<T> Twhen(T mock)Allows to choose a method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style
-
-
-
Field Detail
-
strictness
private final Strictness strictness
-
answers
private final java.util.List<Answer<?>> answers
-
-
Constructor Detail
-
StubberImpl
public StubberImpl(Strictness strictness)
-
-
Method Detail
-
when
public <T> T when(T mock)
Description copied from interface:StubberAllows to choose a method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() styleExample:
Read more about those methods:doThrow(new RuntimeException()) .when(mockedList).clear(); //following throws RuntimeException: mockedList.clear();See examples in javadoc for
Mockito
-
doReturn
public Stubber doReturn(java.lang.Object toBeReturned)
Description copied from interface:BaseStubberUse it for stubbing consecutive calls inMockito.doReturn(Object)style.See javadoc for
Mockito.doReturn(Object)- Specified by:
doReturnin interfaceBaseStubber- Parameters:
toBeReturned- to be returned when the stubbed method is called- Returns:
- stubber - to select a method for stubbing
-
doReturn
public Stubber doReturn(java.lang.Object toBeReturned, java.lang.Object... nextToBeReturned)
Description copied from interface:BaseStubberUse it for stubbing consecutive calls inMockito.doReturn(Object)style.See javadoc for
Mockito.doReturn(Object, Object...)- Specified by:
doReturnin interfaceBaseStubber- Parameters:
toBeReturned- to be returned when the stubbed method is callednextToBeReturned- to be returned in consecutive calls when the stubbed method is called- Returns:
- stubber - to select a method for stubbing
-
doReturnValues
private StubberImpl doReturnValues(java.lang.Object... toBeReturned)
-
doThrow
public Stubber doThrow(java.lang.Throwable... toBeThrown)
Description copied from interface:BaseStubberUse it for stubbing consecutive calls inMockito.doThrow(Throwable[])style:
See javadoc fordoThrow(new RuntimeException("one")). doThrow(new RuntimeException("two")) .when(mock).someVoidMethod();Mockito.doThrow(Throwable[])- Specified by:
doThrowin interfaceBaseStubber- 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:BaseStubberUse it for stubbing consecutive calls inMockito.doThrow(Class)style:
See javadoc fordoThrow(RuntimeException.class). doThrow(IllegalArgumentException.class) .when(mock).someVoidMethod();Mockito.doThrow(Class)- Specified by:
doThrowin interfaceBaseStubber- Parameters:
toBeThrown- exception class 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, java.lang.Class<? extends java.lang.Throwable>... nextToBeThrown)
Description copied from interface:BaseStubberUse it for stubbing consecutive calls inMockito.doThrow(Class)style:
See javadoc fordoThrow(RuntimeException.class). doThrow(IllegalArgumentException.class) .when(mock).someVoidMethod();Mockito.doThrow(Class)- Specified by:
doThrowin interfaceBaseStubber- Parameters:
toBeThrown- exception class to be thrown when the stubbed method is callednextToBeThrown- exception class next 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:BaseStubberUse it for stubbing consecutive calls inMockito.doNothing()style:
See javadoc fordoNothing(). doThrow(new RuntimeException("two")) .when(mock).someVoidMethod();Mockito.doNothing()- Specified by:
doNothingin interfaceBaseStubber- Returns:
- stubber - to select a method for stubbing
-
doAnswer
public Stubber doAnswer(Answer answer)
Description copied from interface:BaseStubberUse it for stubbing consecutive calls inMockito.doAnswer(Answer)style:
See javadoc fordoAnswer(answerOne). doAnswer(answerTwo) .when(mock).someVoidMethod();Mockito.doAnswer(Answer)- Specified by:
doAnswerin interfaceBaseStubber- 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:BaseStubberUse it for stubbing consecutive calls inMockito.doCallRealMethod()style.See javadoc for
Mockito.doCallRealMethod()- Specified by:
doCallRealMethodin interfaceBaseStubber- Returns:
- stubber - to select a method for stubbing
-
-