Mock aggregate invoke and execute

Hi, I need some help here. Did someone else had the same issue and has found a solution.
E.g. I have a Aggregate called Book and in some external handler test I mock that aggregate using mockito.
Then I want either to mock the response of invoke some method on that aggregate like
when(this.mockedBook.invoke(Book::getTitle)).thenReturn(“someTitle”);
or I want to verify execute of some method with an exact payload on that aggregate
verify(mockedBook).execute(e → e.add(someAddBookCommand));
Both of those don’t work for me.
Any help is appreciated. Thanks

Hello Petar. Could you share some more context about this? Why are you mocking the aggregate?
Most of the time, Axon Framework applications are tested by testing the message contract.
This means verifying something sends a command of a specific set of data from the sender side and testing the aggregate by testing that a command results in a certain set of events.

We do this because the messages are the contract of your aggregate, and we like the aggregate’s implementation to be flexible. So, if we test the commands (input) and the events (output), we don’t need to test the internal state. We test the contracts, and thus the business logic.
If we implement tests like this, we can easily adjust tests for use cases. They are also clear to read, and allow us to easily expand or change functionality within the aggregate.

You can read more about testing aggregates here: Commands / Events - Axon Reference Guide

Kind regards,

Mitchell Herrijgers