Axon 4.0 - Testing Saga (Spring Boot 2.0.5)


I’m trying to test a Saga. I expect when an event occurs then two commands are dispatched.

The assertion is:

        .published(new InvoiceCreated(**...**))

             Matchers.equalTo(new AcceptInvoice(**....**)),
             Matchers.equalTo(new BackupInvoice(**....**))

The problem is that I always get this error:

org.axonframework.test.AxonAssertionError: Incorrect dispatched command. Expected <list with all of: <dto.command.AcceptInvoice> (FAILED!) and <dto.command.BackupInvoice>>, but got

Any idea what could be wrong?



I have already found out where was the problem. I take a look at tests in Axon-Trader and the modified the test to


the problem in your first attempt is that the matchers are compared against the entire message, rather than just the payload. If you only want to match the payloads (which is quite common), you can use Matchers.payloadsMatching(…), which takes a matcher that should match against a list of payloads.

If you just want to verify equality, though, you can also use expectDispatchedCommands(…).