Matchers on aggregate tests in Axon 3

What's the recommended Axon 3 way to express "I expect an event of class X but I don't care about its exact contents" in a command handler test? In Axon 2, I used the expectEventsMatching() method on the test fixture with the Matchers.payloadsMatching() helper, like so:


In Axon 3, this fails to compile because expectEventsMatching() wants a Matcher<List<? extends EventMessage>> but Matchers.payloadsMatching() returns Matcher<List<? extends Message>>.

Not a huge deal to write my own Matchers.payloadsMatching() equivalent that takes the correct types, but if there's another way I should be going about this now, I'd like to know.


Hi Steve

you’re doing it the right way. Apparently, I didn’t get the generics completely correct. After 20 times x super y, y extends z and z super c, you kind of lose track :wink:

I’ve created an issue to fix this: (and fixing it right away)



I am new to Axon and am using 4.0.3. With this exact scenario as Steven was saying, I don’t care the content of the event, just the type. The above approach works, But I am wondering if there is a simpler syntax.
I tried the approach below but Axon fails with the message listed below:

public void testOrderCreated() throws Exception {
            .when(new CreateOrderCommand())

org.axonframework.test.AxonAssertionError: The published events do not match the expected events.Expected :
an instance of
But got:
GenericDomainEventMessage: GenericDomainEventMessage{payload={OrderCreatedEvent(orderId=…

Since the method signature is expectEventsMatching, why not unwrap the GenericDomainEventMessage to an event before doing the comparison.


there is another utility method to tell Axon you’re not interested in the entire message, but just the payload. Simply add: payloadsMatching(…)

In your example:

public void testOrderCreated() throws Exception {
            .when(new CreateOrderCommand())
            .expectEventsMatching(*payloadsMatching(exactSequence(*instanceOf(OrderCreatedEvent.class), andNoMore())));

The exactSequence tells Axon that you expect the events in this order (but there’s only one). The andNoMore() matcher matches against the absence of any more events in the sequence.
(Note: I didn’t use an IDE to write this up. There might be a type or misplaced bracket)


Thanks so much for the response. Yeah that is what I did following Steven’s example for version 2. I could not find any detailed documentation for these types of questions. And it is not very intuitive for developer to figure out these hidden usage of APIs.

Hi cfu8899,

We’re in the know at AxonIQ that the reference guide needs some love to be more fleshed out to cover topics like this.

Any suggestions you might have are very much appreciated.
If you could find the time, it would be ideal if you could mark suggestions like this as issues in the issue tracker.

That way we’re not just adding documentation we think should be there, but also documentation you think should be there.