문제

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!

도움이 되었습니까?

해결책

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())
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top