java - Count method invocation of method variable instance -
i have code this:
class foobar { private string statefoo; public foobar(string statefoo){ this.statefoo = statefoo; } public void foo() { fooinst f = fooinstfactory.createsomefooinst(anotherstaticfooconfig.getsomepath); f.justcountme(); } }
my goal make sure f.justcountme()
executed once. know how in general mockito. don't know how inject mocked version of fooinst
foo
method? can count invocation?
is possible so?
if possible; suggest avoid using mocking libraries temper static fields (in way powermock/mockito do) - comes undesired side effects (for example many "coverage" tools produce invalid results when static mocking takes places).
so suggestion: re-design class under test. instead of fetching f static factory; provide constructor either factory or f; can mock corresponding object; without need turn mighty dangerous "powerxyz" stuff.