- priority: 5 --> 6
Using version 1.8.5 of Mockito - try this in a CallbackParams test-class:
@CallbackField Collection<?> callback;
{
callback = Mockito.spy(callback);
}
The initiative will result in a MockitoException with this message:
Cannot mock/spy class $Proxy9
Mockito cannot mock/spy following:
- final classes
- anonymous classes
- primitive types
In short - callbacks are not eligible candidates for Mockito spying. There is a reason for this - the callbacks are created by using the Java SE API for dynamic proxies. However, there is no good reason to why callbacks should be non-eligible for Mockito spying, so this should be fixed. It is probably easy to fix by creating some hand-rolled dynamic-proxy tools that also provide Mockito with desirable class-implementations for the callback instances.