### Question:
ExchangeRateService { public Map<String, Object> getAllMarketPrices() { Map<String, Object> metadata = new LinkedHashMap<>(); Map<String, ExchangeRate> aggregateExchangeRates = getAggregateExchangeRates(); providers.forEach(p -> { Set<ExchangeRate> exchangeRates = p.get(); metadata.putAll(getMetadata(p, exchangeRates)); }); LinkedHashMap<String, Object> result = new LinkedHashMap<>(); result.putAll(metadata); List<ExchangeRate> values = new ArrayList<>(aggregateExchangeRates.values()); values.sort(Comparator.comparing(ExchangeRate::getCurrency)); result.put("data", values); return result; } ExchangeRateService(List<ExchangeRateProvider> providers); Map<String, Object> getAllMarketPrices();  }### Answer:
@Test public void getAllMarketPrices_withNoExchangeRates_logs_Exception() { int numberOfCurrencyPairsOnExchange = 0; ExchangeRateProvider dummyProvider = buildDummyExchangeRateProvider(numberOfCurrencyPairsOnExchange); ExchangeRateService service = new ExchangeRateService(Collections.singletonList(dummyProvider)); Map<String, Object> retrievedData = service.getAllMarketPrices(); doSanityChecksForRetrievedDataSingleProvider(retrievedData, dummyProvider, numberOfCurrencyPairsOnExchange); assertEquals(0L, retrievedData.get(dummyProvider.getPrefix() + "Ts")); List<ILoggingEvent> logsList = ((ListAppender) exchangeRateServiceLogger.getAppender(LIST_APPENDER_NAME)).list; assertEquals(Level.ERROR, logsList.get(0).getLevel()); assertTrue(logsList.get(0).getMessage().endsWith("No exchange rate data found for " + dummyProvider.getName())); }
@Test public void getAllMarketPrices_withSingleExchangeRate() { int numberOfCurrencyPairsOnExchange = 1; ExchangeRateProvider dummyProvider = buildDummyExchangeRateProvider(numberOfCurrencyPairsOnExchange); ExchangeRateService service = new ExchangeRateService(Collections.singletonList(dummyProvider)); Map<String, Object> retrievedData = service.getAllMarketPrices(); doSanityChecksForRetrievedDataSingleProvider(retrievedData, dummyProvider, numberOfCurrencyPairsOnExchange); assertNotEquals(0L, retrievedData.get(dummyProvider.getPrefix() + "Ts")); }
@Test public void getAllMarketPrices_withMultipleProviders_differentCurrencyCodes() { int numberOfCurrencyPairsOnExchange = 1; ExchangeRateProvider dummyProvider1 = buildDummyExchangeRateProvider(numberOfCurrencyPairsOnExchange); ExchangeRateProvider dummyProvider2 = buildDummyExchangeRateProvider(numberOfCurrencyPairsOnExchange); ExchangeRateService service = new ExchangeRateService(asList(dummyProvider1, dummyProvider2)); Map<String, Object> retrievedData = service.getAllMarketPrices(); doSanityChecksForRetrievedDataMultipleProviders(retrievedData, asList(dummyProvider1, dummyProvider2)); assertNotEquals(0L, retrievedData.get(dummyProvider1.getPrefix() + "Ts")); assertNotEquals(0L, retrievedData.get(dummyProvider2.getPrefix() + "Ts")); }
@Test public void getAllMarketPrices_withMultipleProviders_overlappingCurrencyCodes() { Set<String> rateCurrencyCodes = Sets.newHashSet("CURRENCY-1", "CURRENCY-2", "CURRENCY-3"); ExchangeRateProvider dummyProvider1 = buildDummyExchangeRateProvider(rateCurrencyCodes); ExchangeRateProvider dummyProvider2 = buildDummyExchangeRateProvider(rateCurrencyCodes); ExchangeRateService service = new ExchangeRateService(asList(dummyProvider1, dummyProvider2)); Map<String, Object> retrievedData = service.getAllMarketPrices(); doSanityChecksForRetrievedDataMultipleProviders(retrievedData, asList(dummyProvider1, dummyProvider2)); assertNotEquals(0L, retrievedData.get(dummyProvider1.getPrefix() + "Ts")); assertNotEquals(0L, retrievedData.get(dummyProvider2.getPrefix() + "Ts")); }