Jmockit:无法将 returns() 用于集合和多次调用?
Jmockit: impossible to use returns() with collections and multiple calls?
我要模拟的函数:
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?? */);
}};
要么写
new Expectations() {{ bar.getFoos(); returns(foo1, foo2, foo3); }};
到return一组,或
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); }};
到return一组序列。
我要模拟的函数:
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?? */);
}};
要么写
new Expectations() {{ bar.getFoos(); returns(foo1, foo2, foo3); }};
到return一组,或
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); }};
到return一组序列。