updating credit amount functionality
This commit is contained in:
@@ -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());
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user