Using Spring's MockMvc framework, how do I test the value of an attribute of an attribute of my model?
You can nest hasItem
and hasProperty
matchers if your object has a getter getMyProperty
.
.andExpect(model().attribute("MyObjectForm",
hasProperty("myObjects",
hasItem(hasProperty("myProperty”, Matchers.equalTo(true))))))
If you know how much objects are in the list than you can check the first item with
.andExpect(model().attribute("MyObjectForm",
hasProperty("myObjects", contains(
hasProperty("myProperty”, Matchers.equalTo(true)),
any(MyObject.class),
...
any(MyObject.class)))));