【发布时间】:2014-05-26 10:41:17
【问题描述】:
我有以下地图:
Map<String, MyCustomObject>
我的目标是使用 hamcrest 匹配器验证此地图的容量。我尝试了以下方法:
assertThat(map, hasEntry("key", (MyCustomObject)hasItem(hasProperty("propertyName", equalTo("value")))));
但看起来hasItem 方法只适用于集合。
是否有其他方法可以验证自定义对象?
new MyCustomObject() 在我的情况下不起作用,因为测试因哈希码相等而失败。还有,我不能修改MyCustomObject class。
【问题讨论】: