我有一些这样的代码:
class FooBar {
private String stateFoo;
public FooBar(String stateFoo){
this.stateFoo = stateFoo;
}
public void foo() {
FooInst f = FooInstFactory.createSomeFooInst(AnotherStaticFooConfig.getSomePath);
f.justCountMe();
}
}
我的目标是确保f.justCountMe()
只执行一次。我知道如何用 mockito 来做这件事。我不知道如何将模拟版本FooInst
注入foo
方法中?这样我就可以计算调用?
甚至有可能这样做吗?