Skip to content

Create OkHttp3 Response for testing

Use a variation of the following code to create a Response to test with:

private Response createResponse()
    {
        HttpUrl mHttpUrl = new HttpUrl.Builder()
                .scheme("https")
                .host("example.com")
                .build();
        Request mRequest = new Request.Builder()
                .url(mHttpUrl)
                .build();

        Response.Builder builder = new Response.Builder()
                .request(mRequest)
                .protocol(Protocol.HTTP_1_1)
                .message("message")
                .code(302);

        return builder.build();
    }

 

Published inJavaProgramming

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *