我有类
的方法interface Class1{
void method1(SomeObject... parameters);
}
我有一个自定义的Hamcrest匹配器
public class SomeObjectMatcher extends BaseMatcher<SomeObject>{...}
如何编写期望匹配传递给method1的对象
SomeObject someObject = new SomeObject(...);
...
mockery.checking(new Expectations(){{
oneOf(class1).method1(with(new SomeObjectMatcher(someObject1)));
}}
实际通话
class1.method1(someObject);
传递的对象和期望的对象是相同的,但SomeObjectMatcher失败,因为实际传递的参数不是someObject1,而是SomeObject [] {someObject1}(只有一个对象的数组 - someObject1)? 有没有办法在链中添加新的匹配器,如
oneOf(class1).method1(with(arrayHas(new SomeObjectMatcher(someObject1))));
答案 0 :(得分:1)
尝试将arrayHas
替换为hasItemInArray
。要匹配数组中的多个项目,您可以使用arrayContaining
和arrayContainingInAnyOrder
。