本文整理汇总了Java中retrofit2.mock.NetworkBehavior.setVariancePercent方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkBehavior.setVariancePercent方法的具体用法?Java NetworkBehavior.setVariancePercent怎么用?Java NetworkBehavior.setVariancePercent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类retrofit2.mock.NetworkBehavior
的用法示例。
在下文中一共展示了NetworkBehavior.setVariancePercent方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provideRetrofit
import retrofit2.mock.NetworkBehavior; //导入方法依赖的package包/类
@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();
}
示例2: provideBehavior
import retrofit2.mock.NetworkBehavior; //导入方法依赖的package包/类
@Provides @Singleton NetworkBehavior provideBehavior(@NetworkDelay Preference<Long> networkDelay,
@NetworkFailurePercent Preference<Integer> networkFailurePercent,
@NetworkVariancePercent Preference<Integer> networkVariancePercent) {
NetworkBehavior behavior = NetworkBehavior.create();
behavior.setDelay(networkDelay.get(), MILLISECONDS);
behavior.setFailurePercent(networkFailurePercent.get());
behavior.setVariancePercent(networkVariancePercent.get());
return behavior;
}
示例3: provideNetworkBehavior
import retrofit2.mock.NetworkBehavior; //导入方法依赖的package包/类
@Provides
public NetworkBehavior provideNetworkBehavior() {
final NetworkBehavior networkBehavior = NetworkBehavior.create();
networkBehavior.setDelay(2, TimeUnit.SECONDS);
networkBehavior.setVariancePercent(20);
networkBehavior.setFailurePercent(0);
return networkBehavior;
}
示例4: setup
import retrofit2.mock.NetworkBehavior; //导入方法依赖的package包/类
@Before
public void setup() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(LyftPublicApi.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<LyftPublicApi> lyftApidelegate = mockRetrofit.create(LyftPublicApi.class);
lyftPublicApi = spy(new MockLyftPublicApi(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());
}
示例5: networkBehaviour
import retrofit2.mock.NetworkBehavior; //导入方法依赖的package包/类
private NetworkBehavior networkBehaviour(Metadata<RxRetrofit> metadata) {
RxRetrofit retrofit = metadata.getAnnotation();
NetworkBehavior networkBehavior = NetworkBehavior.create();
networkBehavior.setDelay(retrofit.delay(), TimeUnit.MILLISECONDS);
networkBehavior.setVariancePercent(retrofit.variancePercentage());
networkBehavior.setFailurePercent(retrofit.failurePercent());
return networkBehavior;
}
示例6: networkBehaviour
import retrofit2.mock.NetworkBehavior; //导入方法依赖的package包/类
private NetworkBehavior networkBehaviour(Metadata<Rx2Retrofit> metadata) {
Rx2Retrofit retrofit = metadata.getAnnotation();
NetworkBehavior networkBehavior = NetworkBehavior.create();
networkBehavior.setDelay(retrofit.delay(), TimeUnit.MILLISECONDS);
networkBehavior.setVariancePercent(retrofit.variancePercentage());
networkBehavior.setFailurePercent(retrofit.failurePercent());
return networkBehavior;
}
示例7: networkBehaviour
import retrofit2.mock.NetworkBehavior; //导入方法依赖的package包/类
private NetworkBehavior networkBehaviour(Metadata<Retrofit> metadata) {
Retrofit retrofit = metadata.getAnnotation();
NetworkBehavior networkBehavior = NetworkBehavior.create();
networkBehavior.setDelay(retrofit.delay(), TimeUnit.MILLISECONDS);
networkBehavior.setVariancePercent(retrofit.variancePercentage());
networkBehavior.setFailurePercent(retrofit.failurePercent());
return networkBehavior;
}
示例8: getNetworkBehavior
import retrofit2.mock.NetworkBehavior; //导入方法依赖的package包/类
private static NetworkBehavior getNetworkBehavior(int delayMsec, int delayVariance,
int failurePercent, int errorPercent) {
NetworkBehavior networkBehavior = NetworkBehavior.create();
networkBehavior.setDelay(delayMsec, TimeUnit.MILLISECONDS);
networkBehavior.setVariancePercent(delayVariance);
// "failure" means network layer failure
networkBehavior.setFailurePercent(failurePercent);
// "error" means HTTP error
networkBehavior.setErrorPercent(errorPercent);
return networkBehavior;
}
示例9: provideBehavior
import retrofit2.mock.NetworkBehavior; //导入方法依赖的package包/类
@Provides
@ApplicationScope
NetworkBehavior provideBehavior(@NetworkDelay Preference<Long> networkDelay,
@NetworkFailurePercent Preference<Integer> networkFailurePercent,
@NetworkVariancePercent Preference<Integer> networkVariancePercent) {
NetworkBehavior behavior = NetworkBehavior.create();
behavior.setDelay(networkDelay.get(), MILLISECONDS);
behavior.setFailurePercent(networkFailurePercent.get());
behavior.setVariancePercent(networkVariancePercent.get());
return behavior;
}
示例10: provideBehavior
import retrofit2.mock.NetworkBehavior; //导入方法依赖的package包/类
@Provides @Singleton NetworkBehavior provideBehavior(@NetworkDelay Preference<Long> networkDelay,
@NetworkVariancePercent Preference<Integer> networkVariancePercent,
@NetworkFailurePercent Preference<Integer> networkFailurePercent,
@NetworkErrorPercent Preference<Integer> networkErrorPercent,
Preference<NetworkErrorCode> networkErrorCode) {
NetworkBehavior behavior = NetworkBehavior.create();
behavior.setDelay(networkDelay.get(), MILLISECONDS);
behavior.setVariancePercent(networkVariancePercent.get());
behavior.setFailurePercent(networkFailurePercent.get());
behavior.setErrorPercent(networkErrorPercent.get());
behavior.setErrorFactory(
() -> Response.error(networkErrorCode.get().code, ResponseBody.create(null, new byte[0])));
return behavior;
}