Starting with jMock 2.6, I can make sure my mock objects are seen consistently by multiple threads via
final Mockery mockery = new Mockery();
mockery.setThreadingPolicy(new Synchroniser());
What are my options (I'm experiencing intermittent test "flakes") when using jMock 2.5?
Particularly, is it sufficient (update: no, doesn't play well with expectations) to wrap all mock object method invocations using synchronized
?
<T> T synchronizedMock(final T mock,
final Class<T> clazz) {
return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[] {clazz, CaptureControl.class},
(proxy, method, args) -> {
synchronized (mock) {
return method.invoke(mock, args);
}
});
}
When using the above approach, what are my chances to run into any deadlocks?