io.magentys.rest.model.RestAssuredResponse Maven / Gradle / Ivy
package io.magentys.rest.model;
import io.restassured.response.Response;
import java.util.function.Supplier;
public class RestAssuredResponse implements RestResponse {
private final Response response;
private final T data;
public RestAssuredResponse(final Response response, final T data) {
this.response = response;
this.data = data;
}
public RestAssuredResponse(final Response response) {
this(response, null);
}
@Override
public T data() {
return data;
}
@Override
public int statusCode() {
return response.statusCode();
}
@Override
public Body body() {
return RestAssuredBody.from(response.body());
}
@Override
public boolean failed() {
return !ok();
}
@Override
public boolean ok() {
return statusCode() < 400;
}
public static RestResponse constructFrom(Response response, Supplier data) {
return response.statusCode() >= 400 ? new RestAssuredResponse<>(response) : new RestAssuredResponse<>(response, data.get());
}
}