### Question:
FeeRateService { public Map<String, Object> getFees() { Map<String, Long> metadata = new HashMap<>(); Map<String, Long> allFeeRates = new HashMap<>(); AtomicLong sumOfAllFeeRates = new AtomicLong(); AtomicInteger amountOfFeeRates = new AtomicInteger(); providers.forEach(p -> { FeeRate feeRate = p.get(); String currency = feeRate.getCurrency(); if ("BTC".equals(currency)) { sumOfAllFeeRates.getAndAdd(feeRate.getPrice()); amountOfFeeRates.getAndAdd(1); } }); long averageFeeRate = (amountOfFeeRates.intValue() > 0) ? sumOfAllFeeRates.longValue() / amountOfFeeRates.intValue() : FeeRateProvider.MIN_FEE_RATE; averageFeeRate = Math.max(averageFeeRate, FeeRateProvider.MIN_FEE_RATE); averageFeeRate = Math.min(averageFeeRate, FeeRateProvider.MAX_FEE_RATE); metadata.put("bitcoinFeesTs", Instant.now().getEpochSecond()); allFeeRates.put("btcTxFee", averageFeeRate); return new HashMap<>() {{ putAll(metadata); put("dataMap", allFeeRates); }}; } FeeRateService(List<FeeRateProvider> providers); Map<String, Object> getFees();  }### Answer:
@Test public void getFees_noWorkingProvider() { List<FeeRateProvider> listOfProviders = new ArrayList<>(); for (int i = 0; i < 3; i++) { try { listOfProviders.add(buildDummyUnreachableMempoolFeeRateProvider()); } catch (Exception e) { log.info("We encountered an expected exception: " + e.getMessage()); } } FeeRateService service = new FeeRateService(listOfProviders); Map<String, Object> retrievedData = service.getFees(); doSanityChecksForRetrievedData(retrievedData, FeeRateProvider.MIN_FEE_RATE); }
@Test public void getFees_singleProvider_feeBelowMin() { long providerFee = FeeRateProvider.MIN_FEE_RATE - 3; FeeRateService service = new FeeRateService( Collections.singletonList( buildDummyReachableMempoolFeeRateProvider(providerFee))); Map<String, Object> retrievedData = service.getFees(); doSanityChecksForRetrievedData(retrievedData, FeeRateProvider.MIN_FEE_RATE); }
@Test public void getFees_singleProvider_feeAboveMax() { long providerFee = FeeRateProvider.MAX_FEE_RATE + 13; FeeRateService service = new FeeRateService( Collections.singletonList( buildDummyReachableMempoolFeeRateProvider(providerFee))); Map<String, Object> retrievedData = service.getFees(); doSanityChecksForRetrievedData(retrievedData, FeeRateProvider.MAX_FEE_RATE); }
@Test public void getFees_multipleProviders() { FeeRateService service = new FeeRateService(asList( buildDummyReachableMempoolFeeRateProvider(FeeRateProvider.MIN_FEE_RATE * 1), buildDummyReachableMempoolFeeRateProvider(FeeRateProvider.MIN_FEE_RATE * 2), buildDummyReachableMempoolFeeRateProvider(FeeRateProvider.MIN_FEE_RATE * 3))); Map<String, Object> retrievedData = service.getFees(); doSanityChecksForRetrievedData(retrievedData, FeeRateProvider.MIN_FEE_RATE * 2); }