views:

48

answers:

0

Hello,

I used the code from this blog to inject Mockito mocks in my unit tests. However, before the mock is autowired it gets wrapped by Spring in a JDK proxy. This causes any verify(autowiredMock) to throw "Argument passed to verify() is not a mock!". The exception is thrown when Mockito is checking that the argument passed to verify(..) is a valid Mockito mock object in this method:

private static Method getCallbacksSetter(Class type, String methodName) throws NoSuchMethodException {
    return type.getDeclaredMethod(methodName, new Class[]{ Callback[].class });
}

My question is how to tell Spring not to proxy Mockito mock beans which I register in the BeanFactoryPostProcessor? Please note that I would like to avoid setting proxy-target-class="true".

Thanks