I'm trying to create a class in which a Function interface (java.util.function.Function) is passed through the constructor and it seems like I'm almost there but I'm getting an "Incompatible types: Object is not convertible to RequestOptions" error when I actually pass it into the object as a parameter.
The line I'm referring to is:
public static final Request testReqAnswers = new Request(SA_URL, 200, answersEndpoint, Requests::postStatusCode, getFunnelAnswersQueries(advisorMatchQueries, funnelResponseValues));
Am I passing it incorrectly?
Below are all of the relevant code blocks
public static boolean CheckStatusCodeRelook(Request request, Object... requestObj) {
String requestURL = request.environ + request.endpoint + ((requestObj.length > 0) ? requestObj[0].toString() : "");
StringWriter requestWriter = new StringWriter();
PrintStream requestCapture = new PrintStream(new WriterOutputStream(requestWriter));
RequestOptions options = new RequestOptions(requestURL, new RequestLoggingFilter(requestCapture));
int statusCode = (int) request.serializer.apply(options);
requestCapture.flush();
extentReportLog(requestWriter, String.valueOf(statusCode));
return statusCode == request.statuscode;
}
public class Requests extends Base {
public static int postStatusCode(RequestOptions options) {
return given()
.filter(options.filter)
.spec(customRequest)
.post(options.requestUrl)
.statusCode();
}
}
public class Request<T> {
int environ;
int statuscode;
String endpoint;
Function<RequestOptions, Integer> serializer;
//Function<RequestOptions, Object> serializer; This doesn't work but could in theory right?
Class<?> toBeSerialized;
public Request(int environ, int statuscode, String endpoint, Function<RequestOptions, Integer> serializer, Class<?> toBeSerialized) {
this.environ = environ;
this.statuscode = statuscode;
this.endpoint = endpoint;
this.serializer = serializer;
this.toBeSerialized = toBeSerialized;
}
}
public static final Request testReqAnswers = new Request(URL, 200, endpoint, Requests::postStatusCode, getQueries(Queries, Values));