我们希望确认一个自定义对象列表中是否包含一个对象,该对象的某些字段具有特定的值,并进行一系列此类断言。
有没有现成的方案来克服这个问题,还是需要使用某种自定义匹配器来处理?
assertThat(customObjectList, hasItem(hasProperty("someField", equalTo(someValue))));
然而,自定义对象也有布尔类型字段,其中getter方法的前缀为“is”,而不是“get”,在那里断言似乎失败了。
java.lang.AssertionError: Expected: a collection containing hasProperty("booleanField", <true>) but: property "booleanField" is not readable
有没有现成的方案来克服这个问题,还是需要使用某种自定义匹配器来处理?
Boolean
对象? - Ruben