### Question:
FiatService { public double getUsdPrice(TokenValueDto... funds) { return Arrays.stream(funds) .filter(f -> f != null && StringUtils.isNotBlank(f.getTokenSymbol())) .map(this::getValue) .mapToDouble(f -> f) .sum(); } FiatService(CryptoCompareService cryptoCompareService, CoinMarketCapService coinMarketCapService); double getUsdPrice(TokenValueDto... funds);  }### Answer:
@Test public void getUsdPriceOneCryptoCompare() { TokenValueDto totalFund = TokenValueDto.builder().tokenAddress("0x0").tokenSymbol("FND").totalAmount(BigDecimal.TEN).build(); when(coinMarketCapService.getCurrentPriceInUsd("FND")).thenReturn(Optional.empty()); when(cryptoCompareService.getCurrentPriceInUsd("FND")).thenReturn(Optional.of(0.56)); double result = fiatService.getUsdPrice(totalFund); assertThat(result).isEqualTo(5.6); }
@Test public void getUsdPriceMultipleCryptoCompare() { TokenValueDto totalFund1 = TokenValueDto.builder().tokenAddress("0x0").tokenSymbol("FND").totalAmount(new BigDecimal("8457.858")).build(); TokenValueDto totalFund2 = TokenValueDto.builder().tokenAddress("0x0").tokenSymbol("ZRX").totalAmount(new BigDecimal("123.464")).build(); when(coinMarketCapService.getCurrentPriceInUsd("FND")).thenReturn(Optional.empty()); when(coinMarketCapService.getCurrentPriceInUsd("ZRX")).thenReturn(Optional.empty()); when(cryptoCompareService.getCurrentPriceInUsd("FND")).thenReturn(Optional.of(0.56)); when(cryptoCompareService.getCurrentPriceInUsd("ZRX")).thenReturn(Optional.of(0.98)); double result = fiatService.getUsdPrice(totalFund1, totalFund2); assertThat(result).isEqualTo(4857.3952); }
@Test public void coinMarketCapHasPriority() { TokenValueDto totalFund = TokenValueDto.builder().tokenAddress("0x0").tokenSymbol("FND").totalAmount(BigDecimal.TEN).build(); when(coinMarketCapService.getCurrentPriceInUsd("FND")).thenReturn(Optional.of(0.56)); double result = fiatService.getUsdPrice(totalFund); assertThat(result).isEqualTo(5.6); verifyZeroInteractions(cryptoCompareService); }
@Test public void cryptoCompareIsFallback() { TokenValueDto totalFund = TokenValueDto.builder().tokenAddress("0x0").tokenSymbol("FND").totalAmount(BigDecimal.TEN).build(); when(coinMarketCapService.getCurrentPriceInUsd("FND")).thenReturn(Optional.empty()); when(cryptoCompareService.getCurrentPriceInUsd("FND")).thenReturn(Optional.of(0.56)); double result = fiatService.getUsdPrice(totalFund); assertThat(result).isEqualTo(5.6); verify(coinMarketCapService).getCurrentPriceInUsd("FND"); verify(cryptoCompareService).getCurrentPriceInUsd("FND"); }