Testing 测试一个数组是否包含来自另一个具有Hamcrest的数组的元素

Testing 测试一个数组是否包含来自另一个具有Hamcrest的数组的元素,testing,rest-assured,hamcrest,Testing,Rest Assured,Hamcrest,我实际上有两种类型的数据: a = ["1", "2", "3", "3", "5"] b = ["7", "2"] given() .header("Content-Type", "application/json"). when() .post(this.url). then() .statusCode(200) .contentType("application/json") .body(myPathToData, e

我实际上有两种类型的数据:

a = ["1", "2", "3", "3", "5"]
b = ["7", "2"]

given()
       .header("Content-Type", "application/json").
when()
       .post(this.url).
then()
       .statusCode(200)
       .contentType("application/json")
       .body(myPathToData, everyItem(haveOneOrMoreElementFrom(a)));
我想用Hamcrest在我的身体响应中测试我的放心请求后,b(元素接收)是否包含来自a的一个或多个元素(
haveOneOrMoreElementFrom,在我的示例中)

也可能在我的身体反应中发挥作用吗

解决方案:

我找到了一个可能的解决方案:
everyItem(hasItem(isIn(a))
我认为检查
b
是否至少包含
a
中的一个元素的解决方案是

assertThat(b, hasItemInArray(isIn(a))); // for arrays

assertThat(b, hasItem(isIn(a))); // for collections
如果你放心,那就太好了

...

then()
       .body(pathToData, hasItem(isIn(a)));

在Hamcrest 2中,不推荐使用
org.Hamcrest.Matchers::isIn
方法,因此建议使用
is(在(a)中)
或只使用
In(a)