### Question:
CurrencySum { public synchronized CurrencyValue getSumAsCurrency(String targetCurrency, ExchangeRateProvider exchangeRateProvider) { CurrencyValue sum = ExactCurrencyValue.from(BigDecimal.ZERO, targetCurrency); for (Map.Entry<String, CurrencyValue> value : buckets.entrySet()) { if (value.getValue() != null) { CurrencyValue sumLocal = sum.add(value.getValue(), exchangeRateProvider); if(sumLocal.getValue() != null) { sum = sumLocal; } } } return sum; }  synchronized void add(CurrencyValue valueToAdd); synchronized void add(CurrencySum sumToAdd); synchronized Map<String, CurrencyValue> getAllValues(); synchronized CurrencyValue getSumAsCurrency(String targetCurrency, ExchangeRateProvider exchangeRateProvider);  }### Answer:
@Test public void testGetSumAsCurrency() throws Exception { ExactCurrencyValue b1 = ExactCurrencyValue.from(BigDecimal.ONE, CurrencyValue.BTC); ExactCurrencyValue b2 = ExactCurrencyValue.from(BigDecimal.valueOf(2L), CurrencyValue.BTC); ExactCurrencyValue f1 = ExactFiatValue.from(BigDecimal.valueOf(3L), "USD"); ExactCurrencyValue f2 = ExactFiatValue.from(BigDecimal.valueOf(4L), "USD"); ExactCurrencyValue f3 = ExactFiatValue.from(BigDecimal.valueOf(5L), "EUR"); CurrencySum currencySum = new CurrencySum(); currencySum.add(b1); currencySum.add(b2); currencySum.add(f1); currencySum.add(f2); currencySum.add(f3); CurrencyValue sumAsCurrency = currencySum.getSumAsCurrency(CurrencyValue.BTC, fx); AssertHelper.assertRoundedEqualValue(BigDecimal.valueOf(5), sumAsCurrency.getValue(), 8); assertEquals(sumAsCurrency.getCurrency(), "BTC"); CurrencyValue sumAsCurrencyUSD = currencySum.getSumAsCurrency("USD", fx); AssertHelper.assertRoundedEqualValue(BigDecimal.valueOf(35), sumAsCurrencyUSD.getValue(), 8); assertEquals("USD", sumAsCurrencyUSD.getCurrency()); }