org.axonframework.test.AxonAssertionError: One of the events contained different values than expected

I added a timestamp field to my Event and now the unit test fails. Even though the expected and actual are the exact same?

@Test
public void shouldCreateAggregateAndRaiseDemandEvent() throws Exception {
    String sku = "303";
    fixture
            .given()
            .when(new StockItemSVSupplyCommand(sku, 8))
            .expectReturnValue(null)
            .expectEvents(new StockItemCreatedEvent(sku,0), new StockItemSupplyEvent(sku, 8));
}


Abstract Event Object

The problem is that your command handler which handles StockItemSVSupplyCommand produces the published events and they are not at the exact same instant of the events you create in: .expectEvents(new StockItemCreatedEvent(sku,0), new StockItemSupplyEvent(sku, 8)).

The real issue here is that you shouldn’t add a timestamp to your events. The way to get the timestamp of the event is to annotate a parameter of your event handler method with @Timestamp (org.axonframework.eventhandling.Timestamp).

Here is a sample event handler method from one of my view updaters:

`

@EventHandler
public void on(WeightDimsCapturedEvent event, @SequenceNumber long aggregateVersion,
@Timestamp Instant occurrenceInstant) {
PkgQO pkgQO = repository.findOne(event.getPkgId());
pkgQO.updateAggregateVersion(aggregateVersion);
pkgQO.addWeightDims(event.getWeightDims());
pkgQO.updateLastModified(event.getAgentId(), occurrenceInstant);
repository.save(pkgQO);
}

`

So as you can see, I update my view with the timestamp of the event occurrence. Also, note that I get the aggregate version (the sequence number of the event within the aggregate stream).

Ah Troy, like that, thanks mate.

Great solution.