• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mocking deep down with mockito

 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?


 
I am going to test your electrical conductivity with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic