This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Testing and the fly likes EasyMock - How to mock the cast operation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "EasyMock - How to mock the cast operation" Watch "EasyMock - How to mock the cast operation" New topic

EasyMock - How to mock the cast operation

Girish kamath

Joined: Sep 07, 2010
Posts: 1
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

Joined: May 26, 2003
Posts: 32819

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeff Storey
Ranch Hand

Joined: Apr 07, 2007
Posts: 230
You could also use the EasyMock class extensions to make your mock an instanceof SqlMapClientImpl (since I assume SqlMapClientImpl implements the SqlMapClient interface).

Jeff Storey
Software Developer
I agree. Here's the link:
subject: EasyMock - How to mock the cast operation
It's not a secret anymore!