https://kotlinlang.org logo
#android
Title
# android
j

jishindev

09/12/2018, 6:48 AM
#test
r

rkeazor

09/12/2018, 9:05 AM
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

Nawin

09/12/2018, 9:29 AM
@rkeazor I am the same person on stackoverflow 😄. Which dependency do I need to mock?
r

rkeazor

09/12/2018, 11:54 AM
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

Nawin

09/12/2018, 11:59 AM
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

rkeazor

09/12/2018, 12:29 PM
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
2 Views