Wednesday, May 6, 2015

EasyMock Exceptions when mocking Classes instead of Interfaces

EasyMock as the name suggests, provides an easy way to mock objects for testing where-in you mock interfaces of the classes you want to test. EasyMock then generates mock objects on the fly using Java's proxy mechanism and then simulates it in a simple way and also verifies whether it is used as expected.
When creating some new mock objects for testing using EasyMock 2.5.x, I noticed the below exceptions:
java.lang.IllegalArgumentException: org.hibernate.dialect.Dialect is not an interface
 at java.lang.reflect.Proxy.getProxyClass0(
 at java.lang.reflect.Proxy.newProxyInstance(
 at org.easymock.internal.JavaProxyFactory.createProxy(
 at org.easymock.internal.MocksControl.createMock(
 at org.easymock.EasyMock.createMock(

To solve this, change your import as:
org.easymock.EasyMock.createMock => org.easymock.classextension.EasyMock.createMock

And another set of exceptions popped up:
java.lang.IllegalArgumentException: not a proxy instance
 at java.lang.reflect.Proxy.getInvocationHandler(
 at org.easymock.EasyMock.getControl(
 at org.easymock.EasyMock.replay(

To solve this, change your imports as:
org.easymock.EasyMock.replay => org.easymock.classextension.EasyMock.replay
org.easymock.EasyMock.verify => org.easymock.classextension.EasyMock.verify

Viola! and now we are good!
When mocking classes that are not an interface, we need to use the createMock, replay, and verify methods FROM the class org.easymock.classextension.EasyMock and NOT the ones we regularly use from org.easymock.EasyMock
However, since EasyMock 3.0, the separate classextension package has been deprecated and left in place for backward compatibility and the above changes are not required. So it is recommended that if possible, one should upgrade to the latest 3.x version of EasyMock instead of going for the above changes.


sheela rajesh said...

I am very proud to read such an informative blog. i Will follow your updates in future so, please add more and more ideas.
Python Training in Chennai
Python Training in Tambaram
Big data training in chennai
JAVA Training in Chennai
Selenium Training in Chennai
Software testing training in chennai
Python Training in Annanagar

Kayal said...

Thank you for giving the innovative post, Keep posting and sharing with us....!
Corporate Training in Chennai
Corporate Training institute in Chennai
Excel Training in Chennai
Embedded System Course Chennai
Oracle DBA Training in Chennai
Linux Training in Chennai
job vacancy in chennai
Power BI Training in Chennai
Corporate Training in TNagar

Logical softTech said...

Your post is very good. I got to learn a lot from your post. Thank you for sharing your article for us. it is amazing post
what is seo
types of seo

Howdy said...

You will definitely like them Dubai Escorts Look and make sure!

Chris Hemsworth said...

I have been reading for the past two days about your blogs and topics, still on fetching! Wondering about your words on each line was massively effective. Techno-based information has been fetched in each of your topics. Sure it will enhance and fill the queries of the public needs. Feeling so glad about your article. Thanks…!
best software testing training in chennai
best software testing training institute in chennai with placement
software testing training

software testing training and placement
software testing training online
software testing class
software testing classes in chennai
best software testing courses in chennai
automation testing courses in chennai
digital marketing training in chennai
digital marketing classes in chennai
digital marketing course in chennai
digital marketing institute in chennai
digital marketing training centers in chennai
digital marketing training institute in chennai
best digital marketing course in chennai

nisharoshan said...

Nice article I was really impressed by seeing this blog, it was very interesting and it is very useful for me.

Web Designing Training in Chennai

Web Designing Course in Chennai

Web Designing Training in Bangalore

Web Designing Course in Bangalore

Web Designing Training in Hyderabad

Web Designing Course in Hyderabad

Web Designing Training in Coimbatore

Web Designing Training

Web Designing Online Training

Keerthi SK said...

I was following your blog regularly and this one is very interesting and knowledge attaining. Great effort ahead. you can also reach us for web development company in chennai website design company in chennai

Let2know said...

GlassWire Crack is a new application or service accessing the Internet for the first time? GlassWire Elite Crack politely alerts GlassWire Elite Keygen

cyber pc said...

Mega Downloader APK provides user-controlled encrypted cloud storage space and talk from side to side normal web browsers, jointly with devoted apps for mobile strategy. Click Here

Hurrain said...

This blog is great and has a lot of useful information.

Mudassara Shahzad said...

This article makes me very happy to read. Thanks for the great information.
Acronis True Image


Related Posts Plugin for WordPress, Blogger...