Package org.mockito.internal.stubbing
Class VoidMethodStubbableImpl<T>
- java.lang.Object
-
- org.mockito.internal.stubbing.VoidMethodStubbableImpl<T>
-
- All Implemented Interfaces:
VoidMethodStubbable<T>
public class VoidMethodStubbableImpl<T> extends java.lang.Object implements VoidMethodStubbable<T>
-
-
Constructor Summary
Constructors Constructor Description VoidMethodStubbableImpl(T mock, InvocationContainerImpl invocationContainerImpl)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
on()
Choose void method for stubbing.VoidMethodStubbable<T>
toAnswer(Answer<?> answer)
Stubs a void method with genericAnswer
VoidMethodStubbable<T>
toReturn()
Stubs void method to 'just return' (e.g.VoidMethodStubbable<T>
toThrow(java.lang.Throwable throwable)
Stubs void method with an exception.
-
-
-
Constructor Detail
-
VoidMethodStubbableImpl
public VoidMethodStubbableImpl(T mock, InvocationContainerImpl invocationContainerImpl)
-
-
Method Detail
-
toThrow
public VoidMethodStubbable<T> toThrow(java.lang.Throwable throwable)
Description copied from interface:VoidMethodStubbable
Stubs void method with an exception. E.g:
If throwable is a checked exception then it has to match one of the checked exceptions of method signature. See examples in javadoc forstubVoid(mock).toThrow(new RuntimeException()).on().someMethod();
Mockito.stubVoid(T)
- Specified by:
toThrow
in interfaceVoidMethodStubbable<T>
- Parameters:
throwable
- to be thrown on method invocation- Returns:
- VoidMethodStubbable - typically to choose void method and finish stubbing
-
toReturn
public VoidMethodStubbable<T> toReturn()
Description copied from interface:VoidMethodStubbable
Stubs void method to 'just return' (e.g. to not to throw any exception)Only use this method if you're stubbing consecutive calls.
For example:
stubVoid(mock) .toReturn() .toThrow(new RuntimeException()) .on().foo(10);
- first time foo(10) is called the mock will 'just return' (e.g. don't throw any exception)
- second time foo(10) is called the mock will throw RuntimeException
- every consecutive time foo(10) is called the mock will throw RuntimeException
See examples in javadoc for
Mockito.stubVoid(T)
- Specified by:
toReturn
in interfaceVoidMethodStubbable<T>
- Returns:
- VoidMethodStubbable - typically to choose void method and finish stubbing
-
toAnswer
public VoidMethodStubbable<T> toAnswer(Answer<?> answer)
Description copied from interface:VoidMethodStubbable
Stubs a void method with genericAnswer
For Example:
stubVoid(mock) .toAnswer(new Answer() { public Object answer(InvocationOnMOck invocation) { Visitor v = (Visitor) invocation.getArguments()[0]; v.visitMock(invocation.getMock()); return null; } }) .on().accept(any());
- Specified by:
toAnswer
in interfaceVoidMethodStubbable<T>
- Parameters:
answer
- the custom answer to execute.- Returns:
- VoidMethodStubbable - typically to choose void method and finish stubbing
-
on
public T on()
Description copied from interface:VoidMethodStubbable
Choose void method for stubbing. E.g:
See examples in javadoc forstubVoid(mock).toThrow(new RuntimeException()).on().someMethod("some arg");
Mockito.stubVoid(T)
- Specified by:
on
in interfaceVoidMethodStubbable<T>
- Returns:
- mock object itself
-
-