Call Real Method
Mock not void method:
Mockito.when(jsonResponseValidator.validate(any(DefaultResponse.class))).thenCallRealMethod()
Mock void method:
Mockito.doCallRealMethod().when(jsonResponseValidator).validate(any(DefaultResponse.class));
You can use any of the doReturn(), doThrow(), doAnswer(),doNothing(), doCallRealMethod() family of methods.
Do Throw
Mock void method with doThrow():
...
@Mock
privare TransferSender transferSender;
...
Transfer transfer = new Transfer();
Mockito.doThrow(new MyException("kabooom!").when(transferSender).send(transfer);
source:
Mockito API
Brak komentarzy:
Prześlij komentarz