Unit testing with EasyMock and Spring
Let's come up with simple test scenario. I have two Spring Service implementations with corresponding interfaces. I like to test only the process method in FooServiceImp class in isolation. The problem is FooServiceImp.peocess() calls FooBarService.process() method which I don't want to test with this peticular Unit test. So how do I test just FooServiceImp.process() method without testing FooBarService. EasyMock is to rescue. Before the testing I can replace the reference of FooBarService to a EasyMock object and add certain expected behavior to the Mock. Behaviors I like to add to mock: 1. The return value of the Mock service. 2. Capture the parameters passed to the Mock Service. 3. Add a Exception to test Exception scenario Here are the codes. Happy Unit Testing: FooServiceTest.java import static org.junit.Assert.*; import java.util.List; import org.easymock.Capture; import org.easymock.EasyMock; import org.junit.Before; import org.junit.Test; import or...