Created Sunday 27 April 2014
- add a setter method that allows you to replace an object that gets created in the constructor
Unfortunately, this approach has several downsides when you don't use Spring or another IoC framework:
- You are adding a setter that should be called only in unit tests
- The original dependency is still instantiated
- Breaks encapsulation
Alternatives
- use an Ioc framework
- use reflection to set the value of the object in the unit test