當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。