Saga testing - static reference in SagaMethodMessageHandlerInspector

Hi all,

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?



Okay, for now I worked around the issue by writing some simple reflection code clearing the static maps in


Is there anything else that should be cleaned?


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.



Thanks, I must have missed that method when I was looking for references to the static variable. I'll check it out tomorrow.