本文整理汇总了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());
}