MoneyTransferService { public MoneyTransfer createMoneyTransfer(MoneyTransferInfo moneyTransferInfo) { MoneyTransfer mt = new MoneyTransfer(moneyTransferInfo); moneyTransferRepository.save(mt); createTransferMoneySaga(mt.getId(), moneyTransferInfo); return mt; } MoneyTransferService(MoneyTransferRepository moneyTransferRepository, SagaManager<TransferMoneySagaState> transferMoneySagaManager); MoneyTransfer createMoneyTransfer(MoneyTransferInfo moneyTransferInfo); Optional<MoneyTransfer> findMoneyTransfer(long id); void completeTransfer(long moneyTransferId); void cancelTransfer(long moneyTransferId);  }
@Test public void shouldCreateMoneyTransfer() { when(moneyTransferRepository.save(any(MoneyTransfer.class))).thenAnswer(invocation -> { ((MoneyTransfer)invocation.getArguments()[0]).setId(MoneyTransferMother.moneyTransferId); return null; }); MoneyTransfer moneyTransfer = moneyTransferService.createMoneyTransfer(moneyTransferInfo); verify(moneyTransferRepository).save(moneyTransfer); verify(transferMoneySagaManager).create(any(TransferMoneySagaState.class)); }