@Override public String getProcessedPaymentRate() { final Currency currency = getProcessedCurrency(); if (currency == null) { return null; } // If there were multiple payments (and refunds) we pick chose the last one DateTime latestPaymentDate = null; final Iterator<InvoicePayment> paymentIterator = ((DefaultInvoice) invoice).getPayments().iterator(); while (paymentIterator.hasNext()) { final InvoicePayment cur = paymentIterator.next(); latestPaymentDate = latestPaymentDate != null && latestPaymentDate.isAfter(cur.getPaymentDate()) ? latestPaymentDate : cur.getPaymentDate(); } try { final CurrencyConversion conversion = currencyConversionApi.getCurrencyConversion(currency, latestPaymentDate); for (Rate rate : conversion.getRates()) { if (rate.getCurrency() == getCurrency()) { return rate.getValue().toString(); } } } catch (CurrencyConversionException e) { logger.warn("Failed to retrieve currency conversion rates for currency = " + currency + " and date = " + latestPaymentDate, e); return null; } logger.warn("Failed to retrieve currency conversion rates for currency = " + currency + " and date = " + latestPaymentDate); return null; }
Mockito.when(currencyConversion.getRates()).thenReturn(rates); try { Mockito.when(currencyConversionApi.getCurrencyConversion(Mockito.<Currency>any(), Mockito.<DateTime>any())).thenReturn(currencyConversion); } catch (CurrencyConversionException e) { throw new RuntimeException(e);