我想重構這個 Java/RestAssured 代碼以完全洗掉 if 陳述句
if (someCondition) {
someRequestSpecification
.given()
.queryParam(THING, theThing)
.queryParam(SPECIAL_THING, anotherThing)
.get()
} else {
someRequestSpecification
.given()
.queryParam(THING, theThing)
.get()
}
換句話說,我希望能夠完全基于條件省略 SPECIAL_THING 引數,但不必復制 .given() 代碼。
目前我的代碼在 if 陳述句中處理重復的行,但它很難看。
uj5u.com熱心網友回復:
你可以像這樣重構。
RequestSpecification reSpec = given().queryParam(THING, theThing);
if(condition){
reSpec.queryParam(SPECIAL_THING, anotherThing);
}
reSpec.get();
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/525747.html
