Skip to content

Question: Clarification on use of ArgumentCaptor: captor.getValue().onResponse(null, res)  #6

@deeps2

Description

@deeps2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions