'. '

Talk:Injectable Singleton

From APIDesign

(Difference between revisions)
Jump to: navigation, search
(Andrei Badea said ...)
Line 7: Line 7:
--Andrei Badea 11:52, 12 February 2010 (CET)
--Andrei Badea 11:52, 12 February 2010 (CET)
</div>
</div>
 +
 +
Simple answer is that Lookup.getDefault() is in fact a "meta-singleton", so you can have a testing implementation that will allow you to do what you want. I am still looking for more complex answer that would use ''mockito''.
 +
 +
--[[User:JaroslavTulach|JaroslavTulach]] 12:08, 18 March 2010 (UTC)

Revision as of 12:08, 18 March 2010

Questions?

Andrei Badea said ...

Often the MockDialogDisplayer used in tests will be configurable. For example, it may have a constructor taking a parameter that says whether the yesOrNo() method returns true or false. So in a test I create an instance of MockDialogDisplayer, as opposed to letting ServiceLoader or the Lookup library create it. When I hold such an instance, how do I set it as the singleton instance?

--Andrei Badea 11:52, 12 February 2010 (CET)

Simple answer is that Lookup.getDefault() is in fact a "meta-singleton", so you can have a testing implementation that will allow you to do what you want. I am still looking for more complex answer that would use mockito.

--JaroslavTulach 12:08, 18 March 2010 (UTC)

Personal tools
buy