Samuel Carrijo
Samuel Carrijo

Reputation: 17949

Mocking a concrete class using EasyMock

Is it possible to mock a concrete class using EaskMock? If so, how do I do it?

Upvotes: 7

Views: 16671

Answers (5)

Jon Skeet
Jon Skeet

Reputation: 1504022

See the EasyMock Class Extension documentation and download it from the SourceForge project. You can't mock final methods though.

EDIT: This is now part of EasyMock for v3 and above, as noted in comments.

Upvotes: 11

Jay Bose
Jay Bose

Reputation: 1601

When creating a mock, simply use the org.easymock.classextension version of the EasyMock class. The result will be castable.

Here's a recent link - http://easymock.org/EasyMock3_2_ClassExtension_Documentation.html

Upvotes: 0

Mike Partridge
Mike Partridge

Reputation: 5281

EasyMock class extensions have been integrated into EasyMock as of v3.0; see the release notes.

Upvotes: 3

Rich Seller
Rich Seller

Reputation: 84088

Powermock extends EasyMock and allows you to mock concrete types, even final and static methods.

PowerMock is a framework that extend other mock libraries such as EasyMock with more powerful capabilities. PowerMock uses a custom classloader and bytecode manipulation to enable mocking of static methods, constructors, final classes and methods, private methods, removal of static initializers and more.

Upvotes: 7

Related Questions