File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Problem creating mock using PowerMock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Problem creating mock using PowerMock" Watch "Problem creating mock using PowerMock" New topic

Problem creating mock using PowerMock

Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
I am using following in my pom.xml

I get this exception:

then i added javassist to my pom.xml like this:

I've got rid of that problem but now I get another exception while trying to use PowerMock.createMock() method. Here is my code to create mock. its simple:

Exception i get is:

Any idea what am i doing wrong?

David Newton

Joined: Sep 29, 2008
Posts: 12617

Does PowerMock automatically take advantage of ClassExtension?
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Thanks for your reply. Don't know to be honest I am still learning but looking at the example on their website, it looks like we can mock classes having final methods etc using PowerMock.createMock method. Have a look at
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Fixed the problem It looks like PowerMock 1.4.5 is not compatible with easymock 2.2. It works with EasyMock 3.0 as easymock 3.0 doesn't use class extensions anymore separately it is built into it. Also it needs javassist 3.12.0.GA. Thanks.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

Thanks for sharing the solution Ali.

[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
I agree. Here's the link:
subject: Problem creating mock using PowerMock
It's not a secret anymore!