File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes mocking deep down with mockito Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "mocking deep down with mockito" Watch "mocking deep down with mockito" New topic
Author

mocking deep down with mockito

Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30400
    
150

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?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

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

Joined: Oct 21, 2008
Posts: 1107

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?


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mocking deep down with mockito