Hamcrest:如何测试对象中的多个多个属性

lch*_*lch 1 java assert hamcrest

rules=[{type:"path", value:"abc"},{type:"cookie", value:"xyz"}, ...]
Run Code Online (Sandbox Code Playgroud)

我想查找数组是否包含具有属性 ( type=pathand value=abc)的对象

我试过这样的事情: assertThat(rules, hasItem(hasProperty("type", equals("path"))));

但是我没有找到将两种hasProperty方法结合起来的方法。有人能帮我吗

df7*_*899 5

以下将尝试将allOf()检查中的每个匹配器应用于 中的每个项目rules

    assertThat(rules,
            hasItem(allOf(hasProperty("type", equalTo("path")),
                    hasProperty("value", equalTo("abc")))));
Run Code Online (Sandbox Code Playgroud)