I am new to Mockito and trying to understand how to use doAnswer
in order to test a void method.
Here's my class with the onDestroy
method to test:
public class TPresenter implements TContract.Presenter {
private CompositeSubscription viewSubscription;
//.......
@Override public void onCreate(.......) {
this.viewSubscription = new CompositeSubscription();
//.......
}
@Override public void onDestroy() {
if(viewSubscription != null && !viewSubscription.isUnsubscribed()) {
viewSubscription.unsubscribe();
}
}
Now I want to write a test for onDestroy()
namely to verify that after executing onDestroy
the subscription is unsubscribed. I found several examples to use doAnswer
for testing void methods, for example here, and also here but I do not understand them.
Please show how to test the method onDestroy
.