Has anyone faced this issue? <https://stackoverflo...
# android
j
#test
r
The issue the person is having(in the stackoverflow link) isnt with Mockito or kotlin... The real reason is that he forgot to stub or mock out a dependency. If your having the same issue I would suggest pointing break points and debugging your tests
n
@rkeazor I am the same person on stackoverflow 😄. Which dependency do I need to mock?
r
Someone already gave you the answer. It's right in front of you. You mocked out repository.updateOrderAfterCompleteCall to complete when called. However if you look at your code, when it completes it calls updateUser in your subscribe method
So you need whenever(repository.updateUser(-1)).thenReturn(Completable.complete()
❤️ 1
n
Ok Thank you
But I still have a confusion. Why do I need to mock updateUser(-1) just to verify the method is being called or not.
Why don't Mockito manages to show default value on such scenario?
@jw Can you please review my issue once? I am not satisifed with the answer.
r
lol There is nothing to review. For one , the default value of any Completable (and all custom objects) is null. it says it in the Mockito documentation. Only primitives like int floats get a non null default value
The reason why your confused is because you consider this disposable = repository.updateOrderAfterCompleteCall(notes, remarks) .subscribe({ view.showOnCompleteCallSuccess() updateUser() }, { view.showError(it) })
as one function
so when you mocked repository.updateOrderAfterCompleteCall, you thought it mocked the whole thing
Its actually two functions, in the form of method changing. so just because you mock repository.updateOrderAfterCompleteCall, doesn’t mean the rest wont happen
so in essence if showOnCompleteCallSuccess is completed. than updateUser will be called. If UpdateUser() is called , when you reach the line of code that says repository.updateUser(-1), since repository is a Mock, and updateUser(-1), was not stubbed out, it will return the default value of all custom objects, which is null lol