2011-11-24 44 views
2

我得到了类Hamcrest匹配的对象...参数

interface Class1{ 
    void method1(SomeObject... parameters); 
} 

的方法,我有一个自定义Hamcrest匹配器

public class SomeObjectMatcher extends BaseMatcher<SomeObject>{...} 

如何编写对象传递给方法1期望值匹配

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

回答

1

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