Next page | Contents page |

EasyMock class extension

EasyMock is designed to work with interfaces, in the way that we have seen. This should encourage us to write all new classes as implementations of interfaces. This is widely considered to be best practice; the Spring framework, amongst others, strongly promotes this idea.

But of course there are many existing classes that do not implement interfaces. Therefore there is a second version of EasyMock's classes in package org.easymock.classextension. Statically importing EasyMock.* from this package enables both class and interface type objects to be mocked. The JAR file containing this requires the more fundamental org.easymock JAR too.

NB: The class extension creates mocks as instances of proxy sub-classes of the real classes. Therefore it will not work with classes or methods declared as final (such as String).

Next page | Contents page |