我有上课的方法

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))));

最佳答案

尝试将arrayHas替换为hasItemInArray。要匹配数组中的多个项目,可以使用arrayContainingarrayContainingInAnyOrder

08-05 17:17