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


Java MockResponse.setResponseCode方法代码示例

本文整理汇总了Java中okhttp3.mockwebserver.MockResponse.setResponseCode方法的典型用法代码示例。如果您正苦于以下问题:Java MockResponse.setResponseCode方法的具体用法?Java MockResponse.setResponseCode怎么用?Java MockResponse.setResponseCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在okhttp3.mockwebserver.MockResponse的用法示例。


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

示例1: getExchangedAwardsInvalid

import okhttp3.mockwebserver.MockResponse; //导入方法依赖的package包/类
@Test
public void getExchangedAwardsInvalid() {
    User user = new User("username", "name", "surname", "[email protected]", "mypass", "mypass");
    user.setUserAuthToken("user-auth-token");

    UserAdapter.setCurrentUser(user);

    MockResponse mockResponse = new MockResponse()
            .setResponseCode(HttpURLConnection.HTTP_BAD_REQUEST);
    mMockWebServer.enqueue(mockResponse);
    mAwardAdapter.getExchangedAwards(
            UserAdapter.getCurrentUser().getUserAuthToken(),
            mListExchangedAwardSimpleCallback);
    verify(mListAwardsSimpleCallbackMock, timeout(1000)).onFailure();

    mockResponse.setResponseCode(HttpURLConnection.HTTP_NOT_FOUND);
    mMockWebServer.enqueue(mockResponse);
    mAwardAdapter.getExchangedAwards(
            UserAdapter.getCurrentUser().getUserAuthToken(),
            mListExchangedAwardSimpleCallback);
    verify(mListAwardsSimpleCallbackMock, timeout(1000)).onFailure();
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:23,代码来源:AwardAdapterImplTest.java

示例2: getUserBadgesInvalid

import okhttp3.mockwebserver.MockResponse; //导入方法依赖的package包/类
@Test
public void getUserBadgesInvalid() {

    MockResponse mockResponse = new MockResponse()
            .setResponseCode(HttpURLConnection.HTTP_BAD_REQUEST);
    mMockWebServer.enqueue(mockResponse);
    mBadgeAdapter.getUserBadges(UserAdapter.getCurrentUser().getUserAuthToken(),
            mListBadgesSimpleCallback);
    verify(mListBadgesSimpleCallback, timeout(1000)).onFailure();

    mockResponse.setResponseCode(HttpURLConnection.HTTP_NOT_FOUND);
    mMockWebServer.enqueue(mockResponse);
    mBadgeAdapter.getUserBadges(UserAdapter.getCurrentUser().getUserAuthToken(),
            mListBadgesSimpleCallback);
    verify(mListBadgesSimpleCallback, timeout(1000)).onFailure();
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:17,代码来源:BadgeAdapterImplTest.java

示例3: testDemoResponseError503

import okhttp3.mockwebserver.MockResponse; //导入方法依赖的package包/类
@Test
public void testDemoResponseError503() {
    reset(mainSceneMock);
    MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource);

    MockResponse response = new MockResponse();
    response.setResponseCode(HttpURLConnection.HTTP_UNAVAILABLE);

    getErrorMockWebServer().enqueue(response);

    presenter.onSceneAdded(mainSceneMock, null);

    testScheduler.triggerActions();

    verify(mainSceneMock, times(0)).setApiText(anyString());
    verify(mainSceneMock, times(1)).showErrorDialog("Fire on the Server");
}
 
开发者ID:ragdroid,项目名称:mockstar,代码行数:18,代码来源:MainPresenterImplTest.java

示例4: onFailureCallbackWhenGetAwardsInvalidRequest

import okhttp3.mockwebserver.MockResponse; //导入方法依赖的package包/类
@Test
public void onFailureCallbackWhenGetAwardsInvalidRequest() {
    MockResponse mockResponse = new MockResponse()
            .setResponseCode(HttpURLConnection.HTTP_BAD_REQUEST);
    mMockWebServer.enqueue(mockResponse);
    mAwardAdapter.getOfferedAwards(mListAwardsSimpleCallbackMock);
    verify(mListAwardsSimpleCallbackMock, timeout(1000)).onFailure();

    mockResponse.setResponseCode(HttpURLConnection.HTTP_NOT_FOUND);
    mMockWebServer.enqueue(mockResponse);
    mAwardAdapter.getOfferedAwards(mListAwardsSimpleCallbackMock);
    verify(mListAwardsSimpleCallbackMock, timeout(1000)).onFailure();
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:14,代码来源:AwardAdapterImplTest.java

示例5: onFailureCallbackWhenGetAwardInvalidRequest

import okhttp3.mockwebserver.MockResponse; //导入方法依赖的package包/类
@Test
public void onFailureCallbackWhenGetAwardInvalidRequest() {
    MockResponse mockResponse = new MockResponse()
            .setResponseCode(HttpURLConnection.HTTP_BAD_REQUEST);
    mMockWebServer.enqueue(mockResponse);
    mAwardAdapter.getOfferedAward(mAward.getAwardAuthToken(), mAwardSimpleCallbackMock);
    verify(mAwardSimpleCallbackMock, timeout(1000)).onFailure();

    mockResponse.setResponseCode(HttpURLConnection.HTTP_NOT_FOUND);
    mMockWebServer.enqueue(mockResponse);
    mAwardAdapter.getOfferedAward(mAward.getAwardAuthToken(), mAwardSimpleCallbackMock);
    verify(mAwardSimpleCallbackMock, timeout(1000)).onFailure();
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:14,代码来源:AwardAdapterImplTest.java

示例6: getRemoteTranslationListObservableIssue

import okhttp3.mockwebserver.MockResponse; //导入方法依赖的package包/类
@Test
public void getRemoteTranslationListObservableIssue() throws Exception {
  MockResponse mockResponse = new MockResponse();
  mockResponse.setResponseCode(500);
  this.mockWebServer.enqueue(mockResponse);

  TestObserver<TranslationList> testObserver = new TestObserver<>();
  this.translationManager.getRemoteTranslationListObservable()
      .subscribe(testObserver);
  testObserver.awaitTerminalEvent();
  testObserver.assertNoValues();
  testObserver.assertError(IOException.class);
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:14,代码来源:TranslationManagerPresenterTest.java

示例7: enqueueMockResponse

import okhttp3.mockwebserver.MockResponse; //导入方法依赖的package包/类
void enqueueMockResponse(int code, String fileName) throws IOException {
  mockResponse = new MockResponse();
  mockResponse.setResponseCode(code);
  String fileContent = obtainContentFromFile(fileName);
  mockResponse.setBody(fileContent);
  server.enqueue(mockResponse);
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:8,代码来源:MockWebServerTest.java

示例8: dispatch

import okhttp3.mockwebserver.MockResponse; //导入方法依赖的package包/类
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
    MockResponse mockResponse = new MockResponse();
    String scenario = getScenario(request);
    if (scenario != null) {
        try {
            mockResponse.setBody(readFile(scenario));
            mockResponse.setResponseCode(200);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return mockResponse;
}
 
开发者ID:ragdroid,项目名称:mockstar,代码行数:15,代码来源:LocalResponseDispatcher.java

示例9: enqueueMockNoResponse

import okhttp3.mockwebserver.MockResponse; //导入方法依赖的package包/类
void enqueueMockNoResponse(int code) throws IOException {
  mockResponse = new MockResponse();
  mockResponse.setResponseCode(code);
  mockResponse.setSocketPolicy(SocketPolicy.NO_RESPONSE);
  server.enqueue(mockResponse);
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:7,代码来源:MockWebServerTest.java

示例10: testDemoResponseError404

import okhttp3.mockwebserver.MockResponse; //导入方法依赖的package包/类
@Test
public void testDemoResponseError404() {
    reset(mainSceneMock);

    MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource);

    MockResponse response = new MockResponse();
    response.setResponseCode(HttpURLConnection.HTTP_NOT_FOUND);

    getErrorMockWebServer().enqueue(response);

    presenter.onSceneAdded(mainSceneMock, null);

    testScheduler.triggerActions();

    verify(mainSceneMock, times(1)).showErrorDialog("Lost!");
    verify(mainSceneMock, times(0)).setApiText(anyString());
}
 
开发者ID:ragdroid,项目名称:mockstar,代码行数:19,代码来源:MainPresenterImplTest.java

示例11: testDemoResponseError403

import okhttp3.mockwebserver.MockResponse; //导入方法依赖的package包/类
@Test
public void testDemoResponseError403() {
    reset(mainSceneMock);

    MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource);

    MockResponse response = new MockResponse();
    response.setResponseCode(HttpURLConnection.HTTP_UNAUTHORIZED);

    getErrorMockWebServer().enqueue(response);

    presenter.onSceneAdded(mainSceneMock, null);

    testScheduler.triggerActions();

    verify(mainSceneMock, times(1)).showErrorDialog("You shall not pass!");
    verify(mainSceneMock, times(0)).setApiText(anyString());
}
 
开发者ID:ragdroid,项目名称:mockstar,代码行数:19,代码来源:MainPresenterImplTest.java


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