Skip to content

Instantly share code, notes, and snippets.

@patrykpoborca
Last active April 5, 2016 01:32
Show Gist options
  • Save patrykpoborca/d8bcd51a03f4556f49e770e3660b4f97 to your computer and use it in GitHub Desktop.
Save patrykpoborca/d8bcd51a03f4556f49e770e3660b4f97 to your computer and use it in GitHub Desktop.
public interface DemoService {
@GET("/somesuffix")
void getData(Callback<List<Data>> callback);
}
public class MockDemoService implements DemoService {
public void getData(Callback<List<Data>> callback){
//do your own implementation for mocking
throw new IllegalStateException("Stub");
}
}
public class NetworkModule {
@Provides
@Singleton
DemoService providesDemoService(@Named("okclient") OkClient okClient) {
return new RestAdapter.Builder()
.setClient(okClient)
.setEndpoint("https://www.yourdomain.com")
.build()
.create(DemoService.class);
}
}
//Simply provide this module to your dagger builder instead of actual module
public class MockNetworkModule extends NetworkModule {
@Override
DemoService providesDemoService(@Named("okclient") OkClient okClient) {
return new MockDemoService();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment