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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -