@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, Stream<String>> req = counter.andThen(r::getLines); WeatherService service = new WeatherService(new WeatherRestfullApi(req::apply)); Location[] locals = service.search("oporto").toArray(size -> new Location[size]); assertEquals(1, count[0]); Stream<WeatherInfo> oportoWeather = of(locals).skip(1).findFirst().get().getPast30daysWeather(); int tempC = oportoWeather .map(WeatherInfo::getTempC) .max(Integer::compareTo) .get(); assertEquals(25, tempC); assertEquals(2, count[0]); of(locals).count(); assertEquals(2, count[0]); }
public Stream<Location> search(String query) { Stream<LocationInfo> locals = api.search(query); return locals.map(this::toLocation); }
WeatherService { public Stream<Location> search(String query) { Stream<LocationInfo> locals = api.search(query); return locals.map(this::toLocation); } }
WeatherService { public Stream<Location> search(String query) { Stream<LocationInfo> locals = api.search(query); return locals.map(this::toLocation); } WeatherService(WeatherApi api);  WeatherService(); }
WeatherService { public Stream<Location> search(String query) { Stream<LocationInfo> locals = api.search(query); return locals.map(this::toLocation); } WeatherService(WeatherApi api);  WeatherService(); Stream<Location> search(String query); }
WeatherService { public Stream<Location> search(String query) { Stream<LocationInfo> locals = api.search(query); return locals.map(this::toLocation); } WeatherService(WeatherApi api);  WeatherService(); Stream<Location> search(String query);  }