Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mocking deep down with mockito

 
Wendy Gibbons
Bartender
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I write a test where the class I need to mock isn't static, and is deep down in the bowls of my application?

sorry I haven't got very far at all yet in my research.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wendy,
This question is hard to answer without an example. On a high level, you abstract something or subclass or ...

Can you provide an example?
 
Wendy Gibbons
Bartender
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ther problem is that all of our code is called by reflection, with intefaces decided years ago. So nothing can be passed in the constructors.
Yesterday I was trying to mock the ElementTemplateMasterService to return a new response. But with this mornings refactor I am only trying to maock the FlexifieldMaster, but it is still an object I have no control over the instantiation of.

This is the test I am trying to fix (currently in progress trying to sort out an answer):


this is the method I am trying to stub out (on FlexiFieldMaster)
 
Wendy Gibbons
Bartender
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well with help I got the previous version to work using doReturn, but then other code after the call caused problems, so I had to stub even higher up and endud up using doNothing.

So my question has become, Is there any good documentation that actually documents this without presuming you are a master of easyMock just converting?


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic