• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EasyMock - How to mock the cast operation

 
Girish kamath
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I mock the cast operation.
I have an cast operation on a dependent object , which will cast to another dependent object like

SqlMapClient sqlMapClient;
SqlMapClientImpl sqlMapClientImpl = (SqlMapClientImpl) sqlMapClient

I' mocking both the dependent clesses i.e SqlMapClient and SqlMapClientImpl .But I need to know how to mock cast using EasyMock.

Any help would be appreciated.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34225
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Girish,
Welcome to JavaRanch!

You can't mock the cast. What you can do is cast to something more generic 9an interface) so both the concrete class and mock can be cast to it.
 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also use the EasyMock class extensions to make your mock an instanceof SqlMapClientImpl (since I assume SqlMapClientImpl implements the SqlMapClient interface).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic