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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -