Announcement Announcement Module
No announcement yet.
Loading JMock objects from ApplicationContext Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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...

  • #2
    You may create a factory bean and inject it into object B. The getObject() method of such bean could return a mock, thus satisfying your requirement.