aspose file tools*
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
JavaRanch » Java Forums » Engineering » Testing
Bookmark "EasyMock - How to mock the cast operation" Watch "EasyMock - How to mock the cast operation" New topic
Author

EasyMock - How to mock the cast operation

Girish kamath
Greenhorn

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

Joined: May 26, 2003
Posts: 30506
    
150

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.


[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
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
[url]http://jeffastorey.blogspot.com[/url]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EasyMock - How to mock the cast operation