当前位置: 首页>>代码示例>>Java>>正文


Java MockRetrofit类代码示例

本文整理汇总了Java中retrofit2.mock.MockRetrofit的典型用法代码示例。如果您正苦于以下问题:Java MockRetrofit类的具体用法?Java MockRetrofit怎么用?Java MockRetrofit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MockRetrofit类属于retrofit2.mock包,在下文中一共展示了MockRetrofit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
@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);
}
 
开发者ID:fooock,项目名称:jshodan,代码行数:15,代码来源:ApiServiceTest.java

示例2: provideRetrofit

import retrofit2.mock.MockRetrofit; //导入依赖的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();
}
 
开发者ID:davideas,项目名称:AndroidBlueprints,代码行数:18,代码来源:ApiModule.java

示例3: provideBusService

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
public static BusService provideBusService(Context context){
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    if (BuildConfig.DEBUG) {
        interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
    } else {
        interceptor.setLevel(HttpLoggingInterceptor.Level.NONE);
    }

    OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(interceptor).build();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(BusService.BASE_URL)
            .client(okHttpClient)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();

    NetworkBehavior behavior = NetworkBehavior.create();
    MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit)
            .networkBehavior(behavior)
            .build();
    behavior.failureException();
    BehaviorDelegate<BusService> delegate = mockRetrofit.create(BusService.class);
    return new MockBusService(context,delegate);
}
 
开发者ID:lowwor,项目名称:Realtime-Bus,代码行数:26,代码来源:Injection.java

示例4: create

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
@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);
        }
    };
}
 
开发者ID:vickychijwani,项目名称:quill,代码行数:18,代码来源:LoginOrchestratorTest.java

示例5: main

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
public static void main(String... args) throws IOException {
  // Create a very simple Retrofit adapter which points the GitHub API.
  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl(SimpleService.API_URL)
      .build();

  // Create a MockRetrofit object with a NetworkBehavior which manages the fake behavior of calls.
  NetworkBehavior behavior = NetworkBehavior.create();
  MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit)
      .networkBehavior(behavior)
      .build();

  BehaviorDelegate<GitHub> delegate = mockRetrofit.create(GitHub.class);
  MockGitHub gitHub = new MockGitHub(delegate);

  // Query for some contributors for a few repositories.
  printContributors(gitHub, "square", "retrofit");
  printContributors(gitHub, "square", "picasso");

  // Using the mock-only methods, add some additional data.
  System.out.println("Adding more mock data...\n");
  gitHub.addContributor("square", "retrofit", "Foo Bar", 61);
  gitHub.addContributor("square", "picasso", "Kit Kat", 53);

  // Reduce the delay to make the next calls complete faster.
  behavior.setDelay(500, TimeUnit.MILLISECONDS);

  // Query for the contributors again so we can see the mock data that was added.
  printContributors(gitHub, "square", "retrofit");
  printContributors(gitHub, "square", "picasso");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:32,代码来源:SimpleMockService.java

示例6: setUp

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
@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);
}
 
开发者ID:fooock,项目名称:jshodan,代码行数:15,代码来源:ExploitServiceTest.java

示例7: provideNetworkRetrofit

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
@Provides
@Singleton
public MockRetrofit provideNetworkRetrofit(Retrofit retrofit, NetworkBehavior networkBehavior) {
    final MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit)
            .networkBehavior(networkBehavior).build();
    return mockRetrofit;
}
 
开发者ID:charafau,项目名称:TurboChat,代码行数:8,代码来源:MockDataModule.java

示例8: MockMessageRepository

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
public MockMessageRepository(Retrofit retrofit, MockRetrofit mockRetrofit,
                             NetworkBehavior networkBehavior) {
    this.networkBehavior = networkBehavior;
    final BehaviorDelegate<MessageApiService> delegate = mockRetrofit.create(MessageApiService.class);

    mockMessageApiService = new MockMessageApiService(delegate);
}
 
开发者ID:charafau,项目名称:TurboChat,代码行数:8,代码来源:MockMessageRepository.java

示例9: setup

import retrofit2.mock.MockRetrofit; //导入依赖的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());
}
 
开发者ID:lyft,项目名称:lyft-android-sdk,代码行数:28,代码来源:LyftButtonCallManagerTest.java

示例10: InbucketTestClient

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
public InbucketTestClient(String baseUrl, int networkFailureProcentage) {
    super(baseUrl);

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseUrl)
            .addConverterFactory(JacksonConverterFactory.create())
            .build();

    NetworkBehavior behavior = NetworkBehavior.create();
    behavior.setFailurePercent(networkFailureProcentage);
    MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit)
            .networkBehavior(behavior)
            .build();

    BehaviorDelegate<InbucketService> delegate = mockRetrofit.create(InbucketService.class);
    service = new InbucketMockService(delegate);


    retrofit = new Retrofit.Builder()
            .baseUrl(baseUrl)
            .build();
    mockRetrofit = new MockRetrofit.Builder(retrofit)
            .networkBehavior(behavior)
            .build();

    delegate = mockRetrofit.create(InbucketService.class);
    simpleService = new InbucketMockService(delegate);
}
 
开发者ID:stepstone-tech,项目名称:inbucket-java-client,代码行数:29,代码来源:InbucketTestClient.java

示例11: setUp

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
@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();
}
 
开发者ID:riggaroo,项目名称:android-retrofit-test-examples,代码行数:15,代码来源:QuoteOfTheDayMockAdapterTest.java

示例12: provideMockRetrofit

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
@Provides
@ApplicationScope
MockRetrofit provideMockRetrofit(Retrofit retrofit, NetworkBehavior behavior) {
    return new MockRetrofit.Builder(retrofit)
            .networkBehavior(behavior)
            .build();
}
 
开发者ID:LiveTyping,项目名称:u2020-mvp,代码行数:8,代码来源:DebugApiModule.java

示例13: provideMockRetrofit

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
@Provides @Singleton MockRetrofit provideMockRetrofit(Retrofit retrofit,
    NetworkBehavior behavior) {
  return new MockRetrofit.Builder(retrofit)
      .networkBehavior(behavior)
      .build();
}
 
开发者ID:rogues-dev,项目名称:superglue,代码行数:7,代码来源:DebugApiModule.java

示例14: provideUserApi

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
@Provides
@Singleton
UserApi provideUserApi(MockRetrofit mockRetrofit) {
    BehaviorDelegate<UserApi> delegate = mockRetrofit.create(UserApi.class);
    return new OfflineUserApi(delegate);
}
 
开发者ID:davideas,项目名称:AndroidBlueprints,代码行数:7,代码来源:ApiModule.java

示例15: provideMessageApi

import retrofit2.mock.MockRetrofit; //导入依赖的package包/类
@Provides
@Singleton
MessageApi provideMessageApi(MockRetrofit mockRetrofit) {
    BehaviorDelegate<MessageApi> delegate = mockRetrofit.create(MessageApi.class);
    return new OfflineMessageApi(delegate);
}
 
开发者ID:davideas,项目名称:AndroidBlueprints,代码行数:7,代码来源:ApiModule.java


注:本文中的retrofit2.mock.MockRetrofit类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。