【发布时间】:2017-03-10 10:57:11
【问题描述】:
谁能帮我将下面的代码重构为 Spring RestTemplate? postLogin 是稍后在junit e2e 测试中使用的方法。
public class LoginLogoutAPI {
private static final LoginLogoutAPI INSTANCE = new LoginLogoutAPI();
private static final String LOGIN_ENDPOINT = "/auth/login";
public static LoginLogoutAPI getInstance() {
return INSTANCE;
}
public ValidatableResponse postLogin(String login, String password) {
return given()
.contentType(JSON)
.body(getCustomerCredentialsJson(login, password))
.when()
.post(LOGIN_ENDPOINT)
.then()
.statusCode(SC_OK);
}
private Map<String, String> getCustomerCredentialsJson(String login, String password) {
Map<String, String> customer = new LinkedHashMap<>();
customer.put("login", login);
customer.put("password", password);
return customer;
}
}
【问题讨论】:
-
你到底想重构什么?整个街区?
-
是的,整个区块
标签: java api resttemplate rest-assured