while writing some test code for sagas I came across the problem that SagaMethodMessageHandlerInspectorS are cached in the static member INSPECTORS in SagaMethodMessageHandlerInspector.
This is a problem if like in my case the CommandBus is used as saga method parameter. If multiple test classes set up their own test fixture with their own command bus and if the second test runs after the first one the command bus from the first test fixture will be passed on as the method parameter instead.
It seems that org.axonframework.common.annotation.MethodMessageHandlerInspector has the same behaviour.
Is there a way to reset these caches for testing purposes or even better get rid of the static caching?
the MethodMessageHandlerInspector is the culprit in your case. You don’t need to use reflection to clear it. There is a static method “clearCache” on it, which you can call in your tests.