Search in sources :

Example 1 with OkHttpResponseBuilder

use of com.github.mjeanroy.junit.servers.utils.builders.OkHttpResponseBuilder in project junit-servers by mjeanroy.

the class OkHttpResponseFactoryTest method it_should_create_http_response.

@Test
void it_should_create_http_response() {
    final Response delegate = new OkHttpResponseBuilder().build();
    final long duration = 1000L;
    final HttpResponse response = OkHttpResponseFactory.of(delegate, duration);
    assertThat(response).isNotNull().isExactlyInstanceOf(OkHttpResponse.class);
    assertThat(response.getRequestDuration()).isEqualTo(duration);
}
Also used : Response(okhttp3.Response) HttpResponse(com.github.mjeanroy.junit.servers.client.HttpResponse) OkHttpResponseBuilder(com.github.mjeanroy.junit.servers.utils.builders.OkHttpResponseBuilder) HttpResponse(com.github.mjeanroy.junit.servers.client.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 2 with OkHttpResponseBuilder

use of com.github.mjeanroy.junit.servers.utils.builders.OkHttpResponseBuilder in project junit-servers by mjeanroy.

the class OkHttpResponseTest method it_should_implement_to_string.

@Test
void it_should_implement_to_string() {
    final Response delegate = new OkHttpResponseBuilder().build();
    final long duration = 1000L;
    final OkHttpResponse response = new OkHttpResponse(delegate.code(), readResponseBody(delegate), delegate.headers(), duration);
    assertThat(response.toString()).isEqualTo("OkHttpResponse{" + "duration: 1000, " + "code: 200, " + "body: \"\", " + "headers: []" + "}");
}
Also used : Response(okhttp3.Response) OkHttpResponseBuilder(com.github.mjeanroy.junit.servers.utils.builders.OkHttpResponseBuilder) Test(org.junit.jupiter.api.Test) AbstractHttpResponseImplTest(com.github.mjeanroy.junit.servers.client.impl.AbstractHttpResponseImplTest)

Example 3 with OkHttpResponseBuilder

use of com.github.mjeanroy.junit.servers.utils.builders.OkHttpResponseBuilder in project junit-servers by mjeanroy.

the class OkHttpResponseTest method it_should_implement_equal_and_hash_code.

@Test
void it_should_implement_equal_and_hash_code() {
    final Response red = new OkHttpResponseBuilder().withStatus(200).build();
    final Response black = new OkHttpResponseBuilder().withStatus(400).build();
    EqualsVerifier.forClass(OkHttpResponse.class).withRedefinedSuperclass().withIgnoredFields("readResponseBodyLock", "_body").withPrefabValues(Response.class, red, black).verify();
}
Also used : Response(okhttp3.Response) OkHttpResponseBuilder(com.github.mjeanroy.junit.servers.utils.builders.OkHttpResponseBuilder) Test(org.junit.jupiter.api.Test) AbstractHttpResponseImplTest(com.github.mjeanroy.junit.servers.client.impl.AbstractHttpResponseImplTest)

Aggregations

OkHttpResponseBuilder (com.github.mjeanroy.junit.servers.utils.builders.OkHttpResponseBuilder)3 Response (okhttp3.Response)3 Test (org.junit.jupiter.api.Test)3 AbstractHttpResponseImplTest (com.github.mjeanroy.junit.servers.client.impl.AbstractHttpResponseImplTest)2 HttpResponse (com.github.mjeanroy.junit.servers.client.HttpResponse)1