Java Code Examples for retrofit2.mock.MockRetrofit#create()

The following examples show how to use retrofit2.mock.MockRetrofit#create() . 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: LoginOrchestratorTest.java    From quill with MIT License 6 votes vote down vote up
@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 2
Source File: ExploitServiceTest.java    From jshodan with MIT License 5 votes vote down vote up
@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 3
Source File: ApiServiceTest.java    From jshodan with MIT License 5 votes vote down vote up
@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 4
Source File: LyftButtonCallManagerTest.java    From lyft-android-sdk with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: ApiModule.java    From AndroidBlueprints with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
UserApi provideUserApi(MockRetrofit mockRetrofit) {
    BehaviorDelegate<UserApi> delegate = mockRetrofit.create(UserApi.class);
    return new OfflineUserApi(delegate);
}
 
Example 6
Source File: ApiModule.java    From AndroidBlueprints with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
MessageApi provideMessageApi(MockRetrofit mockRetrofit) {
    BehaviorDelegate<MessageApi> delegate = mockRetrofit.create(MessageApi.class);
    return new OfflineMessageApi(delegate);
}
 
Example 7
Source File: MockGithubService.java    From u2020 with Apache License 2.0 4 votes vote down vote up
public MockGithubService(MockRetrofit mockRetrofit, MockResponseSupplier responses) {
  this.delegate = mockRetrofit.create(GithubService.class);
  this.responses = responses;
}