当前位置: 首页>>代码示例>>Java>>正文


Java RecordedRequest.getUtf8Body方法代码示例

本文整理汇总了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);
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:22,代码来源:RegisterAdapterTest.java

示例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);
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:22,代码来源:RegisterAdapterTest.java

示例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);
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:20,代码来源:RegisterAdapterTest.java

示例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);
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:20,代码来源:RegisterAdapterTest.java

示例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();
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:28,代码来源:RegisterAdapterTest.java

示例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();

}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:30,代码来源:RegisterAdapterTest.java


注:本文中的okhttp3.mockwebserver.RecordedRequest.getUtf8Body方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。