@Test public void testPastWeatherInOporto(){ Request r = new HttpRequest(); int[] count = {0}; Function<String, String> counter = path -> { count[0]++; System.out.println("Request " + path); return path; }; Function<String, Iterable<String>> req = counter.andThen(r::getLines); WeatherService service = new WeatherService(new WeatherRestfullApi(req::apply)); Iterable<Location> locals = service.search("oporto"); assertEquals(1, count[0]); Iterable<WeatherInfo> oportoWeather = first(skip(locals, 1)).getPast30daysWeather(); int tempC = max(map(oportoWeather, WeatherInfo::getTempC)); assertEquals(22, tempC); assertEquals(2, count[0]); count(locals); assertEquals(2, count[0]); }
public Iterable<Location> search(String query) { Iterable<LocationInfo> locals = api.search(query); return LazyQueries.map(locals, this::toLocation); }
WeatherService { public Iterable<Location> search(String query) { Iterable<LocationInfo> locals = api.search(query); return LazyQueries.map(locals, this::toLocation); } }
WeatherService { public Iterable<Location> search(String query) { Iterable<LocationInfo> locals = api.search(query); return LazyQueries.map(locals, this::toLocation); } WeatherService(WeatherApi api);  WeatherService(); }
WeatherService { public Iterable<Location> search(String query) { Iterable<LocationInfo> locals = api.search(query); return LazyQueries.map(locals, this::toLocation); } WeatherService(WeatherApi api);  WeatherService(); Iterable<Location> search(String query); }
WeatherService { public Iterable<Location> search(String query) { Iterable<LocationInfo> locals = api.search(query); return LazyQueries.map(locals, this::toLocation); } WeatherService(WeatherApi api);  WeatherService(); Iterable<Location> search(String query);  }