Using Retrofit 1 we used to mock web services and simulate network latency as following:
MockRestAdapter mockRestAdapter = MockRestAdapter.from(restAdapter);
return mockRestAdapter.create(MyService.class, new MyServiceMock());
Where MyService
is the service Interface (returning responses as Rx Observables), and MyServiceMock
is a class that implements this interface.
In Retrofit 2.0.0-beta3 there is a brand new mocking system (see: https://github.com/square/retrofit/pull/1343) that is not yet documented. When trying to to something similar I get:
MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit).build();
BehaviorDelegate<AuthService> delegate = mockRetrofit.create(MyService.class);
How do I forward calls to MyServiceMock
?