我想模拟的功能:
class Bar {
public Set<Foo> getFoos();
}
正在测试的代码:
for (int i = 0; i < n; ++i) {
Bar bar = computeBar();
for (Foo f : bar.getFoos()) {
// code
}
}
期望阻止:
new Expectations() {{
bar.getFoos();
returns(/* what should I put here?? */);
}};
答案 0 :(得分:1)
写
new Expectations() {{ bar.getFoos(); returns(foo1, foo2, foo3); }};
返回单个集,或
final Set<Foo> foos1 = new HashSet<Foo>(asList(foo1, foo2));
final Set<Foo> foos2 = new HashSet<Foo>(asList(foo3, foo4, foo5));
new Expectations() {{ bar.getFoos(); returns(foos1, foos2); }};
返回一系列集。