### Question:
LedgersSpiAccountMapper { public SpiTransaction toSpiTransaction(TransactionTO transaction) { return Optional.ofNullable(transaction) .map(t -> new SpiTransaction( t.getTransactionId(), t.getEntryReference(), t.getEndToEndId(), t.getMandateId(), t.getCheckId(), t.getCreditorId(), t.getBookingDate(), t.getValueDate(), toSpiAmount(t.getAmount()), toSpiExchangeRateList(t.getExchangeRate()), t.getCreditorName(), toSpiAccountReference(t.getCreditorAccount()), t.getCreditorAgent(), t.getUltimateCreditor(), t.getDebtorName(), toSpiAccountReference(t.getDebtorAccount()), t.getDebtorAgent(), t.getUltimateDebtor(), t.getRemittanceInformationUnstructured(), MockAccountData.REMITTANCE_UNSTRUCTURED_ARRAY, mapToRemittanceString(t.getRemittanceInformationStructured()), MockAccountData.REMITTANCE_STRUCTURED_ARRAY, t.getPurposeCode(), t.getBankTransactionCode(), t.getProprietaryBankTransactionCode(), MockAccountData.ADDITIONAL_INFORMATION, null, accountBalanceTOToSpiAccountBalance(t.getBalanceAfterTransaction()))) .orElse(null); }  SpiAccountDetails toSpiAccountDetails(AccountDetailsTO accountDetails); SpiCardAccountDetails toSpiCardAccountDetails(AccountDetailsTO accountDetails); abstract List<SpiTransaction> toSpiTransactions(List<TransactionTO> transactions); abstract List<SpiCardTransaction> toSpiCardTransactions(List<TransactionTO> transactions); SpiTransaction toSpiTransaction(TransactionTO transaction); SpiCardTransaction toSpiCardTransaction(TransactionTO transaction); SpiAccountReference toSpiAccountReference(AccountReferenceTO reference); abstract List<SpiAccountBalance> toSpiAccountBalancesList(List<AccountBalanceTO> accountBalanceTOS); @Mapping(target = "spiBalanceType", expression = "java(mapToSpiBalanceType(accountBalanceTO.getBalanceType()))") @Mapping(source = "amount", target = "spiBalanceAmount") abstract SpiAccountBalance accountBalanceTOToSpiAccountBalance(AccountBalanceTO accountBalanceTO); abstract List<SpiExchangeRate> toSpiExchangeRateList(List<ExchangeRateTO> exchangeRates); SpiExchangeRate toSpiExchangeRate(ExchangeRateTO exchangeRate); SpiAmount toSpiAmount(AmountTO amount); abstract FundsConfirmationRequestTO toFundsConfirmationTO(SpiPsuData psuData, SpiFundsConfirmationRequest spiFundsConfirmationRequest); abstract AccountReferenceTO mapToAccountReferenceTO(SpiAccountReference spiAccountReference); String mapToRemittanceString(RemittanceInformationStructuredTO remittanceInformationStructuredTO);  }### Answer:
@Test void toSpiTransactionWithRealData() { TransactionTO inputData = jsonReader.getObjectFromFile("json/mappers/transaction-to.json", TransactionTO.class); SpiTransaction actualResult = ledgersSpiAccountMapper.toSpiTransaction(inputData); SpiTransaction expectedResult = jsonReader.getObjectFromFile("json/mappers/spi-transaction.json", SpiTransaction.class); assertEquals(expectedResult, actualResult); }
@Test void toSpiTransactionWithNull() { SpiTransaction actualResult = ledgersSpiAccountMapper.toSpiTransaction(null); assertNull(actualResult); }