retrofit2.mock.MockRetrofit Java Examples
The following examples show how to use
retrofit2.mock.MockRetrofit.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiModule.java From AndroidBlueprints with Apache License 2.0 | 6 votes |
@Provides @Singleton MockRetrofit provideRetrofit(GsonConverterFactory gson, OkHttpClient okHttpClient) { NetworkBehavior behavior = NetworkBehavior.create(); behavior.setDelay(1, TimeUnit.SECONDS); behavior.setVariancePercent(40); behavior.setErrorPercent(2); Retrofit retrofit = new Retrofit.Builder() .baseUrl(BuildConfig.API_URL) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addCallAdapterFactory(LiveDataCallAdapterFactory.create()) .client(okHttpClient) .build(); return new MockRetrofit.Builder(retrofit) .networkBehavior(behavior) .build(); }
Example #2
Source File: LoginOrchestratorTest.java From quill with MIT License | 6 votes |
@Override public ApiProvider create(String blogUrl) { final Retrofit retrofit = GhostApiUtils.getRetrofit(blogUrl, Helpers.getProdHttpClient()); return new ApiProvider() { @Override public Retrofit getRetrofit() { return retrofit; } @Override public GhostApiService getGhostApi() { MockRetrofit mockRetrofit = Helpers.getMockRetrofit(retrofit, mNetworkBehavior); BehaviorDelegate<GhostApiService> delegate = mockRetrofit.create(GhostApiService.class); return new MockGhostApiService(delegate, mUseGhostAuth); } }; }
Example #3
Source File: ExploitServiceTest.java From jshodan with MIT License | 5 votes |
@Before public void setUp() throws Exception { Retrofit retrofit = new Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .baseUrl("https://exploits.shodan.io/") .build(); MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit) .networkBehavior(networkBehavior).build(); BehaviorDelegate<ExploitService> delegate = mockRetrofit.create(ExploitService.class); apiRestMock = new ExploitServiceMock(delegate); }
Example #4
Source File: ApiServiceTest.java From jshodan with MIT License | 5 votes |
@Before public void setUp() throws Exception { Retrofit retrofit = new Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .baseUrl("https://api.shodan.io/") .build(); MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit) .networkBehavior(networkBehavior).build(); BehaviorDelegate<ApiService> delegate = mockRetrofit.create(ApiService.class); apiRestMock = new ApiRestMock(delegate); }
Example #5
Source File: LyftButtonCallManagerTest.java From lyft-android-sdk with Apache License 2.0 | 5 votes |
@Before public void setup() { Retrofit retrofit = new Retrofit.Builder() .baseUrl(LyftApi.API_ROOT) .build(); NetworkBehavior behavior = NetworkBehavior.create(); behavior.setDelay(1, TimeUnit.MILLISECONDS); behavior.setVariancePercent(0); behavior.setFailurePercent(0); MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit) .networkBehavior(behavior) .build(); BehaviorDelegate<LyftApi> lyftApidelegate = mockRetrofit.create(LyftApi.class); lyftPublicApi = spy(new MockLyftApi(lyftApidelegate)); BehaviorDelegate<GoogleApi> googleApiDelegate = mockRetrofit.create(GoogleApi.class); googleApi = spy(new MockGoogleApi(googleApiDelegate)); HashMap<String, GoogleLatLng> addressToLatLngMap = new HashMap<>(); addressToLatLngMap.put(PICKUP_ADDR, new GoogleLatLng(PICKUP_LAT, PICKUP_LNG)); addressToLatLngMap.put(DROPOFF_ADDR, new GoogleLatLng(DROPOFF_LAT, DROPOFF_LNG)); googleApi.setAddressToLatLngMap(addressToLatLngMap); mockCallback = mock(LyftButton.ResultLoadedCallback.class); callManager = new LyftButtonCallManager("clientId", lyftPublicApi, googleApi, new MockExecutorService()); }
Example #6
Source File: QuoteOfTheDayMockAdapterTest.java From android-retrofit-test-examples with MIT License | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); retrofit = new Retrofit.Builder().baseUrl("http://test.com") .client(new OkHttpClient()) .addConverterFactory(JacksonConverterFactory.create()) .build(); NetworkBehavior behavior = NetworkBehavior.create(); mockRetrofit = new MockRetrofit.Builder(retrofit) .networkBehavior(behavior) .build(); }
Example #7
Source File: DebugApiModule.java From u2020-mvp with Apache License 2.0 | 5 votes |
@Provides @ApplicationScope MockRetrofit provideMockRetrofit(Retrofit retrofit, NetworkBehavior behavior) { return new MockRetrofit.Builder(retrofit) .networkBehavior(behavior) .build(); }
Example #8
Source File: ApiModule.java From AndroidBlueprints with Apache License 2.0 | 4 votes |
@Provides @Singleton UserApi provideUserApi(MockRetrofit mockRetrofit) { BehaviorDelegate<UserApi> delegate = mockRetrofit.create(UserApi.class); return new OfflineUserApi(delegate); }
Example #9
Source File: ApiModule.java From AndroidBlueprints with Apache License 2.0 | 4 votes |
@Provides @Singleton MessageApi provideMessageApi(MockRetrofit mockRetrofit) { BehaviorDelegate<MessageApi> delegate = mockRetrofit.create(MessageApi.class); return new OfflineMessageApi(delegate); }
Example #10
Source File: Helpers.java From quill with MIT License | 4 votes |
@NonNull public static MockRetrofit getMockRetrofit(Retrofit retrofit, NetworkBehavior networkBehavior) { return new MockRetrofit.Builder(retrofit) .networkBehavior(networkBehavior) .build(); }
Example #11
Source File: DebugApiModule.java From u2020 with Apache License 2.0 | 4 votes |
@Provides @Singleton MockRetrofit provideMockRetrofit(Retrofit retrofit, NetworkBehavior behavior) { return new MockRetrofit.Builder(retrofit) .networkBehavior(behavior) .build(); }
Example #12
Source File: DebugApiModule.java From u2020 with Apache License 2.0 | 4 votes |
@Provides @Singleton MockGithubService provideMockGitHubService(MockRetrofit mockRetrofit, MockResponseSupplier responseSupplier) { return new MockGithubService(mockRetrofit, responseSupplier); }
Example #13
Source File: MockGithubService.java From u2020 with Apache License 2.0 | 4 votes |
public MockGithubService(MockRetrofit mockRetrofit, MockResponseSupplier responses) { this.delegate = mockRetrofit.create(GithubService.class); this.responses = responses; }