Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Object argument does not work in method call on mock object  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to mock DAO objects used in a Spring application. I can easily create mock or stub objects and inject them into my service. However, in all cases an object is passed in as an argument and an object is returned as an argument on the method calls in the mock object. I was trying to find a mocking framework that handles this situation. Here is my code with EasyMock. The problem is the Unit object passed to the method on the mock object is created in the service and can not be passed in. When easymock does the compare for the expect, its comparing two different Unit objects with the same values which results in not equal and a failure.




I also tried to handle this in Groovy, which didn't work. I know I can create my own Mock objects for each DAO to handle this. It just seems like a mocking framework should handle this scenario, so I don't have to create the objects. Any ideas on how I should handle this.


Thanks,
Jeff

 
author & internet detective
Posts: 39286
745
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Easymock lets you create a custom matcher rather than using the standard == check. That way you can look at values instead of identity.
 
Does this tiny ad smell okay to you?
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!