selenium 如何在不复制函数调用的情况下编写此条件IF语句?

uqzxnwby  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(160)

我想重构这段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语句中的重复行,但它很难看。

nkoocmlb

nkoocmlb1#

您可以像这样重构。

RequestSpecification reSpec = given().queryParam(THING, theThing);
if(condition){
    reSpec.queryParam(SPECIAL_THING, anotherThing);
}
reSpec.get();

相关问题