|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface VoidMethodStubbable<T>
Stubs void method with an exception. E.g:
stubVoid(mock).toThrow(new RuntimeException()).on().someMethod();
//you can stub with different behavior for consecutive method calls.
//Last stubbing (e.g: toReturn()) determines the behavior for further consecutive calls.
stubVoid(mock)
.toThrow(new RuntimeException())
.toReturn()
.on().someMethod();
See examples in javadoc for Mockito.stubVoid(T)
Method Summary | |
---|---|
T |
on()
Choose void method for stubbing. |
VoidMethodStubbable<T> |
toAnswer(Answer<?> answer)
Stubs a void method with generic Answer |
VoidMethodStubbable<T> |
toReturn()
Stubs void method to 'just return' (e.g. |
VoidMethodStubbable<T> |
toThrow(java.lang.Throwable throwable)
Stubs void method with an exception. |
Method Detail |
---|
VoidMethodStubbable<T> toThrow(java.lang.Throwable throwable)
stubVoid(mock).toThrow(new RuntimeException()).on().someMethod();
If throwable is a checked exception then it has to
match one of the checked exceptions of method signature.
See examples in javadoc for Mockito.stubVoid(T)
throwable
- to be thrown on method invocation
VoidMethodStubbable<T> toReturn()
Only use this method if you're stubbing consecutive calls.
For example:
stubVoid(mock)
.toReturn()
.toThrow(new RuntimeException())
.on().foo(10);
See examples in javadoc for Mockito.stubVoid(T)
VoidMethodStubbable<T> toAnswer(Answer<?> answer)
Answer
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());
answer
- the custom answer to execute.
T on()
stubVoid(mock).toThrow(new RuntimeException()).on().someMethod("some arg");
See examples in javadoc for Mockito.stubVoid(T)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |