updating credit amount functionality

This commit is contained in:
2026-07-05 00:01:19 +02:00
parent 6d48472425
commit a4d210393e
2 changed files with 12 additions and 3 deletions

View File

@@ -35,6 +35,10 @@ public class TransactionService {
private final CurrencyService currencyService;
public BigDecimal calculateCurrencyExchangeValue(CurrencyType from, CurrencyType to, BigDecimal amount) {
if (to == null) {
return BigDecimal.ZERO;
}
Currency debitCurrency = currencyService.findCurrencyByIsoCode(from.name());
Currency creditCurrency = currencyService.findCurrencyByIsoCode(to.name());

View File

@@ -130,10 +130,12 @@ class TransactionServiceTest {
when(currencyService.findCurrencyByIsoCode("USD")).thenReturn(currencyUsd);
when(currencyService.findCurrencyByIsoCode("ZWL")).thenReturn(currencyZwl);
BigDecimal creditAmount = transactionService.calculateCurrencyExchangeValue(transaction);
BigDecimal creditAmount = transactionService.calculateCurrencyExchangeValue(
transaction.getDebitCurrency(),
transaction.getCreditCurrency(),
transaction.getAmount());
assertEquals(new BigDecimal("1500.0000"), creditAmount);
assertEquals(new BigDecimal("1500.0000"), transaction.getCreditAmount());
}
@Test
@@ -141,7 +143,10 @@ class TransactionServiceTest {
void shouldReturnZeroWhenCreditCurrencyNull() {
transaction.setCreditCurrency(null);
BigDecimal result = transactionService.calculateCurrencyExchangeValue(transaction);
BigDecimal result = transactionService.calculateCurrencyExchangeValue(
transaction.getDebitCurrency(),
transaction.getCreditCurrency(),
transaction.getAmount());
assertEquals(BigDecimal.ZERO, result);
}