java - how to unit test a class that uses a factory? -


if have class foo gets objects factory, how unit test foo?

class foo {   void dosth(){     anobject object = factory.instance().getobject();     object.dosth();   } } 

i'm going have call factory in unit test of foo, aren't i?

is spring dependency injection give me advantage, because can do

class foo {   setfactory(factory factory){     this.factory = factory;   }   void dosth(){     anobject object = factory.getobject();     object.dosth();   } } 

or there workaround in non-spring world?


Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -