What is EasyMock WrapperThis is a wrapper for EasyMock 1.x MockControl / EasyMock Class Extension 1.x. The purpose is to mimic the fluent interface of EasyMock 2.x (get rid of Controls) while actually using libraries compatible with Java 1.3. As the helper doesn't extend EasyMock, the functionality offered is limited to version 1.x API, however it is accessed in a 2.x style. Benefits of EasyMock WrapperFluent EasyMock 2.x style API with Java 1.4No need to manage MockControls in your test Easy to migrate to EasyMock 2.x if Java 1.5+ becomes possible for youJust need to change imports. If you use methods that are not in EasyMock 2 like one of the xxxAll then of course you need some refactoring. Mocks interfaces/classes in uniform wayNo need to use MockClassControl for mocking classes Nice resetAll, replayAll, verifyAll convenience methodsHow to useIf you are already using EasyMock then you just need the easymock-wrapper.jar. Sample code: // MockControl is created automatically and stored internally Sample mock = (Sample) EasyMock.createMock(Sample.class); // Chain various andReturn(), andThrow() and times() methods to specify changing behavior EasyMock.expect(mock.isOk()).andReturn(true).times(2).andReturn(false); // Helper will issue replay on the MockControl corresponding to the given mock EasyMock.replayAll(); // your test code ... EasyMock.verifyAll(); Download
|
Add Comment