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