@Test public void maxTemperatureBetweenDatesInALocationTest() throws IOException { final LocalDate fromDate = LocalDate.of(2020, 3, 1); final LocalDate toDate = LocalDate.of(2020, 3, 5); String location = "Lisbon"; WeatherQueries wq = new WeatherQueries(new MemoryWeatherApi()); Iterable<Integer> maxTemperatures = wq.getMaxTemperatures(fromDate, toDate, location); assertNotNull("returned object must not be null", maxTemperatures); int count = 0; for (Integer maxTemperature : maxTemperatures) { ++count; int temp = maxTemperature; assertTrue(temp > -70); assertTrue(temp < 60); } assertEquals(DateUtils.numDays(fromDate, toDate), count); }
public Iterable<Integer> getMaxTemperatures(LocalDate fromDate, LocalDate toDate, String location) throws IOException { Iterable<DailyWeatherInfo> weatherInfos = weatherApi.pastWeather(fromDate, toDate, location); return QueriesEager.map(weatherInfos, dwi -> dwi.getTempMaxC()); }
WeatherQueries { public Iterable<Integer> getMaxTemperatures(LocalDate fromDate, LocalDate toDate, String location) throws IOException { Iterable<DailyWeatherInfo> weatherInfos = weatherApi.pastWeather(fromDate, toDate, location); return QueriesEager.map(weatherInfos, dwi -> dwi.getTempMaxC()); } }
WeatherQueries { public Iterable<Integer> getMaxTemperatures(LocalDate fromDate, LocalDate toDate, String location) throws IOException { Iterable<DailyWeatherInfo> weatherInfos = weatherApi.pastWeather(fromDate, toDate, location); return QueriesEager.map(weatherInfos, dwi -> dwi.getTempMaxC()); } WeatherQueries(WeatherApi weatherApi); }
WeatherQueries { public Iterable<Integer> getMaxTemperatures(LocalDate fromDate, LocalDate toDate, String location) throws IOException { Iterable<DailyWeatherInfo> weatherInfos = weatherApi.pastWeather(fromDate, toDate, location); return QueriesEager.map(weatherInfos, dwi -> dwi.getTempMaxC()); } WeatherQueries(WeatherApi weatherApi); Iterable<Integer> getMaxTemperatures(LocalDate fromDate, LocalDate toDate, String location); Iterable<DailyWeatherInfo> getDailyWeatherInfoWithMaxTemperaturesAbove(LocalDate fromDate, LocalDate toDate, String location, int thresholdTemp); Iterable<DailyWeatherInfo> getDailyWeatherInfoWithMaxTemperaturesBetween(LocalDate fromDate, LocalDate toDate, String location, int min, int max); Iterable<DailyWeatherInfo> getDailyWeatherInfoWithMinTemperaturesAbove(LocalDate fromDate, LocalDate toDate, String location, int thresholdTemp); Iterable<DailyWeatherInfo> getDailyWeatherInfoWithMinTemperaturesBetween(LocalDate fromDate, LocalDate toDate, String location, int min, int max); Iterable<DailyWeatherInfo> queryDailyWeatherInfo(LocalDate fromDate, LocalDate toDate, String location, MyPredicate<DailyWeatherInfo> pred); }
WeatherQueries { public Iterable<Integer> getMaxTemperatures(LocalDate fromDate, LocalDate toDate, String location) throws IOException { Iterable<DailyWeatherInfo> weatherInfos = weatherApi.pastWeather(fromDate, toDate, location); return QueriesEager.map(weatherInfos, dwi -> dwi.getTempMaxC()); } WeatherQueries(WeatherApi weatherApi); Iterable<Integer> getMaxTemperatures(LocalDate fromDate, LocalDate toDate, String location); Iterable<DailyWeatherInfo> getDailyWeatherInfoWithMaxTemperaturesAbove(LocalDate fromDate, LocalDate toDate, String location, int thresholdTemp); Iterable<DailyWeatherInfo> getDailyWeatherInfoWithMaxTemperaturesBetween(LocalDate fromDate, LocalDate toDate, String location, int min, int max); Iterable<DailyWeatherInfo> getDailyWeatherInfoWithMinTemperaturesAbove(LocalDate fromDate, LocalDate toDate, String location, int thresholdTemp); Iterable<DailyWeatherInfo> getDailyWeatherInfoWithMinTemperaturesBetween(LocalDate fromDate, LocalDate toDate, String location, int min, int max); Iterable<DailyWeatherInfo> queryDailyWeatherInfo(LocalDate fromDate, LocalDate toDate, String location, MyPredicate<DailyWeatherInfo> pred);  }