How to use Mockito to test Robospice and Retrofit APIs?

I followed this blog post which shows how to mock queries using Mockito and Retrofit. The problem is that I use both Robospice methods, for which it is not necessary to provide a parameter Callbackin the service interface (since this will be a synchronous call ):

@GET("/foo/bar")
User foo(@Query("bar") String baz);

Therefore, I cannot intercept the callback of my tests as follows:

Mockito.verify(mockApi).repositories(Mockito.anyString(), cb.capture());
User user = new User();
cb.getValue().success(user, null);

Is there any way to achieve this? Thank!

+4
source share
1 answer

The service interface will open, and then the script to return the desired value.

doReturn(new User()).when(service).foo(anyString());

, .

verify(service).foo(anyString())
+5

Source: https://habr.com/ru/post/1531180/


All Articles