public class A {
Integer value;
Integer rate;
Boolean checked;
}
我正在構造一個像這樣的自定義匹配器;
Matchers.hasItems(allOf( hasProperty("value", equalTo(value)), hasProperty("rate", equalTo(rate))))
檢查的A
列表包含了一個與"value" == value && "rate" == rate
我是,當我納入Boolean
type屬性checked
成爲制約這個匹配,它總是失敗的問題錯誤信息msg property "checked" is not readable
。
Matchers.hasItems(allOf( hasProperty("value", equalTo(value)), hasProperty("rate", equalTo(rate)), hasProperty("checked", equalTo(checked))))
是它在某種程度上關係到布爾類型字段的getter方法都is
前綴,而不是get
,並且可以Hamcrest不能用於吸氣is
前綴,如果它不是boolean
但Boolean
類型字段。
此外,我應該補充說我無法修改類A
的結構,因此我堅持使用Boolean
類型字段。