我正在从命令式迁移到响应式模式,并且很难以响应式方式测试我的模拟回调。例如,在服务类中是否可以检查是否调用了模拟程序?
TransactionId transactionId = authorizerApplicationService.newPaymentAuthorization(
new PaymentTransactionCommand(
OPERATION_ID,
TAX_ID));
final ArgumentCaptor<Transaction> argumentsTransaction = ArgumentCaptor.forClass(Transaction.class);
verify(repository, times(2)).save(argumentsTransaction.capture());
final Transaction transaction = argumentsTransaction.getValue();
verify(iamServicePort).authenticate(...));
verify(antiFraudServicePort).checkCustomerSituation(...);
verify(paymentGatewayServicePort, times(0)).authorize(...);
assertEquals(transactionId, transaction.transactionId());
assertEquals(Money.of(100, "BRL"), transaction.amount());
以反应形式:
StepVerifier.create(authorizerApplicationService.newPaymentAuthorization(
new PaymentTransactionCommand(
OPERATION_ID,
TAX_ID)))
.expectNext(OPERATION_ID)
//I need to check here if the mocks were invoked
.verifyComplete();
考虑到我所有的外部服务都返回了Mono of Void,我该如何进行呼叫验证?