aggregate.commitEvents();
DomainEventMessage<StubAggregate> first =
new GenericDomainEventMessage<StubAggregate>(
aggregate.getIdentifier(), aggregate.getVersion(), aggregate);
DomainEventMessage secondEvent = new GenericDomainEventMessage<String>(aggregateIdentifier, (long) 0,
"Mock contents", MetaData.emptyInstance()
);
SimpleDomainEventStream eventStream = new SimpleDomainEventStream(first, secondEvent);
when(mockAggregateFactory.createAggregate(any(), any(DomainEventMessage.class)))
.thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return ((DomainEventMessage)invocation.getArguments()[1]).getPayload();
}
});
DomainEventMessage snapshot = testSubject.createSnapshot("test", aggregateIdentifier, eventStream);
assertSame("Snapshotter did not recognize the aggregate snapshot", aggregate, snapshot.getPayload());
verify(mockAggregateFactory).createAggregate(any(), any(DomainEventMessage.class));
}