java如何用easy mock模拟消费者链接?
试图使用easy mock 3.3.1
测试类Foo
的方法foo
,当链接两个以上的使用者时,它会引发空指针异常
class Foo
{
// init with constructor
Bar1 bar1;
Bar2 bar2;
Bar3 bar3;
FooBar fooBar;
public fooBar foo(){
// line throwing NPE while running unit test.
return fooBar.get(bar1.andThen(bar2).andThen(bar3));
}
}
// Bar2 and Bar 3 has similar implementation
class Bar1 extends Consumer<T> {
@Override
public void accept(T t) {...}
}
// class which accepts consumers.
class FooBar {
public fooBar get(Consumer consumer) {...}
}
// In test class, test method as such
{
expect(fooBar.get(anyObject()).andReturn(MOCKED_OBJ);
// if chaining only two object it works as expected.
// fooBar.get(bar1.andThen(bar2)) its returns MOCKED_OBJ but if chaining more than two its throws NPE
}
共 (0) 个答案