adept-android
adept-android copied to clipboard
Question: Clarification on use of ArgumentCaptor: captor.getValue().onResponse(null, res)
branch: retrofit2-testing
file link: https://github.com/adavis/adept-android/blob/retrofit2-testing/app/src/test/java/info/adavis/adeptandroid/books/books/BooksPresenterTest.java
I have been learning unit testing (Junit, Mockito) for a couple of months now. Found this repo while going through one of the videos on testing retrofit on caster.io. As caster.io is going to be closed soon(received an email regarding the same), so I thought of asking my question here.
My question is regarding ArgumentCaptor.
verify( mockCall ).enqueue( argumentCapture.capture() ); //Line 64
argumentCapture.getValue().onResponse( null, res ); //Line 65
I was going through some examples on StackOverflow and other articles and I couldn't found any example which uses ArgumentCaptor the way it is used here. Here, we are calling a method onResponse()
on captor.getValue()
(passing null
and res
as arguments to onResponse()
). Generally assertions are done on captor.getValue()
something like assertEquals("expected value", captor.getValue())
. Please correct me if I am wrong here.
I am not saying the way captor.getValue()
being used here(calling a method on captor.getValue()
) is wrong. I am just not sure whether ArgumentCaptor provides this additional capability also where you can pass the desired arguments to a function and later assert the behaviour of the test objects. I thought you can just capture the arguments with ArgumentCaptors and can only do assertion on them.