* @param expected The commands expected to have been published on the bus
*/
public void assertDispatchedEqualTo(Object... expected) {
List<CommandMessage<?>> actual = commandBus.getDispatchedCommands();
if (actual.size() != expected.length) {
throw new AxonAssertionError(format(
"Got wrong number of commands dispatched. Expected <%s>, got <%s>",
expected.length,
actual.size()));
}
Iterator<CommandMessage<?>> actualIterator = actual.iterator();
Iterator<Object> expectedIterator = Arrays.asList(expected).iterator();
int counter = 0;
while (actualIterator.hasNext()) {
CommandMessage<?> actualItem = actualIterator.next();
Object expectedItem = expectedIterator.next();
if (expectedItem instanceof CommandMessage) {
CommandMessage<?> expectedMessage = (CommandMessage<?>) expectedItem;
if (!expectedMessage.getPayloadType().equals(actualItem.getPayloadType())) {
throw new AxonAssertionError(format(
"Unexpected payload type of command at position %s (0-based). Expected <%s>, got <%s>",
counter,
expectedMessage.getPayloadType(),
actualItem.getPayloadType()));
}
assertCommandEquality(counter, expectedMessage.getPayload(), actualItem.getPayload());
if (!expectedMessage.getMetaData().equals(actualItem.getMetaData())) {
throw new AxonAssertionError(format(
"Unexpected Meta Data of command at position %s (0-based). Expected <%s>, got <%s>",
counter,
expectedMessage.getMetaData(),
actualItem.getMetaData()));
}