I am trying to get Spring to embed EasyMock mocks in my unit tests.
In my applicationContext.xml, I have this:
<bean id="mockService" class="org.easymock.EasyMock" factory-method="createMock" name="MockService">
<constructor-arg index="0" value="my.project.Service"/>
</bean>
In my unit test, I have this:
@Autowired
@Qualifier("mockService")
private Service service;
public void testGetFoo() {
Foo foo = new Foo();
expect(service.findFoo()).andReturn(foo);
replay(service);
}
When I try to run my test, I get this stack trace:
java.lang.ClassCastException: org.springframework.aop.framework.JdkDynamicAopProxy
at org.easymock.EasyMock.getControl(EasyMock.java:1330)
at org.easymock.EasyMock.replay(EasyMock.java:1279)
at TestFooBar.testGetFoo(TestVodServiceLocator.java:45)
I am completely new to both Spring and EasyMock, but it seems to me that the error is caused by the fact that EasyMock tries to call the method on what, in its opinion, is an instance of EasyMock, but in fact is a dynamic proxy created by Spring. As I understand it, dynamic proxies implement only the methods defined in the interface, in this case, the interface for the Service.
, , ( ), , , -, .
, : ?