RestAssured:如何使POST休息保证为不同类型的Request对象调用abstract

时间:2017-12-12 00:45:08

标签: java rest-assured

目前这是我的帖子:

private static Response postRequest(String endpoint, ABC request, int expectedStatusCode) {
    return extractResponse(buildRequest().body(request).post(endpoint), expectedStatusCode);
}

现在我正在添加另一个帖子端点调用,但请求对象类型不同。像这样:

 private static Response postRequest(String endpoint, XYZ request, int expectedStatusCode) {
    return extractResponse(buildRequest().body(request).post(endpoint), expectedStatusCode);
}

如何在没有冗余代码的情况下重载请求类型?

感谢。

1 个答案:

答案 0 :(得分:1)

使用java generics:

private static <T> Response postRequest(String endpoint, T request, int expectedStatusCode) {...}