PDA

View Full Version : AOP and unit testing



olivier
Jan 10th, 2005, 08:09 AM
Hi,

Is there a way to unit test an advice with JUnit ? I have a problem when I unit test my invoke(MethodInvocation invocation) method, I am not able to create a mock for the object MethodInvocation. Any guess ?

tentacle
Jan 10th, 2005, 10:06 AM
I would guess creating a proxy object in the unit test would be the easiest approach:



ProxyFactory proxyFactory = new ProxyFactory(myTarget);
proxyFactory.addAdvise(myMethodInterceptor);
MyInterface proxy = (MyInterface)proxyFactory.getProxy();

olivier
Jan 10th, 2005, 03:24 PM
yes I am going to work something around that, I don't need any mock, I am just going to use the spring API. Thanks