本文整理匯總了Java中okhttp3.mockwebserver.RecordedRequest.getUtf8Body方法的典型用法代碼示例。如果您正苦於以下問題:Java RecordedRequest.getUtf8Body方法的具體用法?Java RecordedRequest.getUtf8Body怎麽用?Java RecordedRequest.getUtf8Body使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類okhttp3.mockwebserver.RecordedRequest
的用法示例。
在下文中一共展示了RecordedRequest.getUtf8Body方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkValidUnusedEmail
import okhttp3.mockwebserver.RecordedRequest; //導入方法依賴的package包/類
@Test
public void checkValidUnusedEmail() throws InterruptedException {
JsonObject body = new JsonObject();
body.addProperty("message", UserAdapter.USER_DOESNT_EXIST);
mMockServer.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_NOT_FOUND)
.setBody(body.toString()));
ValidationCallback mockCallback = mock(ValidationCallback.class);
mUserAdapter.checkValidUnusedEmail("[email protected]", mockCallback);
RecordedRequest request = mMockServer.takeRequest();
String json = request.getUtf8Body();
JsonObject requestJson = new JsonParser().parse(json).getAsJsonObject();
assertEquals("POST", request.getMethod());
assertEquals("/users/search", request.getPath());
assertEquals("application/json; charset=UTF-8", request.getHeader("Content-Type"));
assertEquals("[email protected]", requestJson.get("email").getAsString());
verify(mockCallback, timeout(1000)).onValidationResponse(UserAdapter.VALID_UNUSED);
}
示例2: checkUsedEmail
import okhttp3.mockwebserver.RecordedRequest; //導入方法依賴的package包/類
@Test
public void checkUsedEmail() throws InterruptedException {
JsonObject body = new JsonObject();
body.addProperty("message", UserAdapter.USER_EXISTS);
mMockServer.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(body.toString()));
ValidationCallback mockCallback = mock(ValidationCallback.class);
mUserAdapter.checkValidUnusedEmail("[email protected]", mockCallback);
RecordedRequest request = mMockServer.takeRequest();
String json = request.getUtf8Body();
JsonObject requestJson = new JsonParser().parse(json).getAsJsonObject();
assertEquals("POST", request.getMethod());
assertEquals("/users/search", request.getPath());
assertEquals("application/json; charset=UTF-8", request.getHeader("Content-Type"));
assertEquals("[email protected]", requestJson.get("email").getAsString());
verify(mockCallback, timeout(1000)).onValidationResponse(UserAdapter.USED);
}
示例3: checkValidUnusedUsername
import okhttp3.mockwebserver.RecordedRequest; //導入方法依賴的package包/類
@Test
public void checkValidUnusedUsername() throws InterruptedException {
JsonObject body = new JsonObject();
body.addProperty("message", UserAdapter.USER_DOESNT_EXIST);
mMockServer.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_NOT_FOUND)
.setBody(body.toString()));
ValidationCallback mockCallback = mock(ValidationCallback.class);
mUserAdapter.checkValidUnusedUsername("validUsername", mockCallback);
RecordedRequest request = mMockServer.takeRequest();
String json = request.getUtf8Body();
JsonObject requestJson = new JsonParser().parse(json).getAsJsonObject();
assertEquals("POST", request.getMethod());
assertEquals("/users/search", request.getPath());
assertEquals("application/json; charset=UTF-8", request.getHeader("Content-Type"));
assertEquals("validUsername", requestJson.get("username").getAsString());
verify(mockCallback, timeout(1000)).onValidationResponse(UserAdapter.VALID_UNUSED);
}
示例4: checkUsedUsername
import okhttp3.mockwebserver.RecordedRequest; //導入方法依賴的package包/類
@Test
public void checkUsedUsername() throws InterruptedException {
JsonObject body = new JsonObject();
body.addProperty("message", UserAdapter.USER_EXISTS);
mMockServer.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(body.toString()));
ValidationCallback mockCallback = mock(ValidationCallback.class);
mUserAdapter.checkValidUnusedUsername("usedUsername", mockCallback);
RecordedRequest request = mMockServer.takeRequest();
String json = request.getUtf8Body();
JsonObject requestJson = new JsonParser().parse(json).getAsJsonObject();
assertEquals("POST", request.getMethod());
assertEquals("/users/search", request.getPath());
assertEquals("application/json; charset=UTF-8", request.getHeader("Content-Type"));
assertEquals("usedUsername", requestJson.get("username").getAsString());
verify(mockCallback, timeout(1000)).onValidationResponse(UserAdapter.USED);
}
示例5: registerNotExistingUser
import okhttp3.mockwebserver.RecordedRequest; //導入方法依賴的package包/類
@Test
public void registerNotExistingUser() throws InterruptedException {
JsonObject body = new JsonObject();
body.addProperty("message", UserAdapter.USER_CREATED);
mMockServer.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_CREATED)
.setBody(body.toString()));
SimpleCallback mockCallback = mock(SimpleCallback.class);
mUserAdapter.registerUser(mUser, mockCallback);
RecordedRequest request = mMockServer.takeRequest();
String json = request.getUtf8Body();
JsonObject requestJson = new JsonParser().parse(json).getAsJsonObject();
assertEquals("POST", request.getMethod());
assertEquals("/users", request.getPath());
assertEquals("application/json; charset=UTF-8", request.getHeader("Content-Type"));
assertEquals("username", requestJson.get("username").getAsString());
assertEquals("name", requestJson.get("first_name").getAsString());
assertEquals("surname", requestJson.get("last_name").getAsString());
assertEquals("[email protected]", requestJson.get("email").getAsString());
assertEquals("a59aea522d1b3a2d0d4b927e4f065909d10a6f8c289901f591644d885aff23ca",
requestJson.get("password").getAsString());
assertEquals("a59aea522d1b3a2d0d4b927e4f065909d10a6f8c289901f591644d885aff23ca",
requestJson.get("password_confirmation").getAsString());
verify(mockCallback, timeout(1000)).onSuccess();
}
示例6: registerExistingUser
import okhttp3.mockwebserver.RecordedRequest; //導入方法依賴的package包/類
@Test
public void registerExistingUser() throws InterruptedException {
JsonObject body = new JsonObject();
body.addProperty("message", UserAdapter.USER_NOT_CREATED);
mMockServer.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_BAD_REQUEST)
.setBody(body.toString()));
SimpleCallback mockCallback = mock(SimpleCallback.class);
mUserAdapter.registerUser(mUser, mockCallback);
RecordedRequest request = mMockServer.takeRequest();
String json = request.getUtf8Body();
JsonObject requestJson = new JsonParser().parse(json).getAsJsonObject();
assertEquals("POST", request.getMethod());
assertEquals("/users", request.getPath());
assertEquals("application/json; charset=UTF-8", request.getHeader("Content-Type"));
assertEquals("username", requestJson.get("username").getAsString());
assertEquals("name", requestJson.get("first_name").getAsString());
assertEquals("surname", requestJson.get("last_name").getAsString());
assertEquals("[email protected]", requestJson.get("email").getAsString());
assertEquals("a59aea522d1b3a2d0d4b927e4f065909d10a6f8c289901f591644d885aff23ca",
requestJson.get("password").getAsString());
assertEquals("a59aea522d1b3a2d0d4b927e4f065909d10a6f8c289901f591644d885aff23ca",
requestJson.get("password_confirmation").getAsString());
verify(mockCallback, timeout(1000)).onFailure();
}