Mar 21st, 2007, 02:46 AM
Loading JMock objects from ApplicationContext
I have an interface implementation (object A) that instantiates a rich business domain object using new (object B), and then delegates responsibility to that domain object to perform a given domain related task. This domain object (object B) then uses Spring to lookup another bean (object C) to perform a different task.
Now I want to mock out object C to ensure it gets called the appropriate number of times and with the correct number of parameters. I also want to create my object C mock in my unit test case to initialise the expected number of calls etc.. but then I need some way of telling Spring to return this mock object (as object C) when my object B looks up object C...
Is there an easy / elegant way of doing this?
P.S I have not seen any docs on people doing this so I have resorted to making object B an interface and injected object C into it at construction time, but this is not really what I want to do...