lch
lch

Reputation: 4931

Hamcrest: How to test for multiple properties of an object

rules=[{type:"path", value:"abc"},{type:"cookie", value:"xyz"}, ...]

I want to find if the array contains an object with properties (type=path and value=abc)

I tried something like this: assertThat(rules, hasItem(hasProperty("type", equals("path"))));

But I didn't find a way to combine two hasProperty methods. Can someone help me

Upvotes: 2

Views: 3151

Answers (1)

df778899
df778899

Reputation: 10931

The following will try to apply each Matcher in the allOf() check to each item in rules:

    assertThat(rules,
            hasItem(allOf(hasProperty("type", equalTo("path")),
                    hasProperty("value", equalTo("abc")))));

Upvotes: 6

Related Questions