CountriesGeoJsonServiceImpl implements CountriesGeoJsonService { public Optional<Double> valueByLocation(Map<String, Double> data, Feature feature) { List<Double> values = entriesByLocation(data, feature).map(Entry::getValue).collect(Collectors.toList()); if (values.isEmpty()) { return Optional.empty(); } Double value = 0.0; for (Double v : values) { value += v; } return Optional.of(value); }  @PostConstruct void setup(); @Override Feature[] getCountries(); @Override String getCountryName(Feature country); @Override String getCountryNameByCode(String code); @Override Optional<Entry<String, Double>> findEntry(Map<String, Double> data, Feature feature); @Override Optional<Double> findValue(Map<String, Double> data, Feature feature); @Override Optional<Feature> findCountry(String idNameOrLocation); Optional<Feature> countryByIdOrName(String idOrName); Optional<Feature> countryByLocation(String location); Optional<Entry<String, Double>> entryByCountry(Map<String, Double> data, Feature value); Optional<Double> valueByCountry(Map<String, Double> data, Feature value); Stream<Entry<String, Double>> entriesByLocation(Map<String, Double> data, Feature feature); Optional<Double> valueByLocation(Map<String, Double> data, Feature feature);  }
@Test public void valueByLocationTest() { when(d3.geoContains(any(), any())).thenReturn(true); Double val = 1d; Optional<Double> valueByLocation; Map<String, Double> data = new HashMap<>(); data.put(COUNTRY_LOCATION, val); valueByLocation = countriesGeoJsonServiceImpl.valueByLocation(data, feature); assertTrue(valueByLocation.isPresent()); assertEquals(val, valueByLocation.get()); verify(d3).geoContains(feature, LONG_LAT); when(d3.geoContains(any(), any())).thenReturn(false); valueByLocation = countriesGeoJsonServiceImpl.valueByLocation(data, null); assertFalse(valueByLocation.isPresent()); valueByLocation = countriesGeoJsonServiceImpl.valueByLocation(new HashMap<>(), null); assertFalse(valueByLocation.isPresent()); }