4

I've been following this blog entry which shows how to mock requests with Mockito and Retrofit. The problem is I'm using both along Robospice, which it doesn't require to provide a Callback as parameter on the service interface (as it would be a synchronous call):

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

So I cannot intercept the callback on my tests on this way:

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

Is any way to achieve this?. Thanks!

Diego Acosta
  • 1,737
  • 3
  • 16
  • 21

1 Answers1

5

Mock the service interface and then script it to return the value you desire.

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

You can later verify that this method was called.

verify(service).foo(anyString())
Jake Wharton
  • 75,598
  • 23
  • 223
  • 230