本文整理匯總了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();
}
示例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();
}
示例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");
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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());
}
示例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());
}