mardi 6 novembre 2018

Call mock method mockito for specific Class

I am wondering to test my interactor and a piece of test code is mocking the Callback interface that is implemented for different objects on BaseInteractor, that all the Interactors implements.

    public interface Callback<T> {

    void onSuccess(T response);

    void onError(Exception exception);

}

I want to test the onSuccess method and i made this:

    @Test
public void shouldGetContributorsSuccess() {

    repository = mock(Repository.class);
    List<Contributor> contributor = getMockContributor();
    GetContributorsInteractor interactor = getFilterReports();
    GetContributorsInteractor.Callback callback = mock(GetContributorsInteractor.Callback.class);

    interactor.execute(contributor.get(0).getUserName(), "Hello_World", callback);

    verify(callback).onSuccess(contributor);
}

when I want to mock the Callback in this line:

    GetContributorsInteractor.Callback callback = mock(GetContributorsInteractor.Callback.class);

after that i call verify(callback).onSuccess(contributor); and show a warning that says Unchecked call to 'onSuccess(T)' as a member of raw type '... .BaseInteractor.Callback'.

I don't know if I should specify in the mock line the specific type as GetContributorsInteractor.Callback but throws an exception or what.

Thanks in advance!

Probably it is because I don't have used mockito before...

Aucun commentaire:

Enregistrer un commentaire