WeatherWebApi { public List<LocationInfo> search(String query) { String path = HOST + String.format(PATH_SEARCH, query, WEATHER_KEY); List<LocationInfo> locations = new ArrayList<>(); Iterator<String> reader = request.getLines(path).iterator(); while (reader.hasNext()) { String line = reader.next(); if(line.startsWith("#")) continue; locations.add(LocationInfo.valueOf(line)); } return locations; } WeatherWebApi(Request request); List<WeatherInfo> pastWeather(double lat, double log, LocalDate from, LocalDate to); List<LocationInfo> search(String query);  }
@Test void search() { List<LocationInfo> infos = new WeatherWebApi(new MockRequest()) .search("Oporto"); assertNotNull(infos); assertFalse(infos.isEmpty()); assertTrue(infos.size() > 0); LocationInfo li = infos.get(1); assertEquals(li.getCountry(), "Portugal"); assertEquals(li.getRegion(), "Porto"); assertEquals(li.getLatitude(), 41.15); assertEquals(li.getLongitude(), -8.617); }
@Test public void search() { List<LocationInfo> infos = new WeatherWebApi(new MockRequest()) .search("Oporto"); assertNotNull(infos); assertFalse(infos.isEmpty()); assertTrue(infos.size() > 0); LocationInfo li = infos.get(1); assertEquals(li.getCountry(), "Portugal"); assertEquals(li.getRegion(), "Porto"); assertEquals(li.getLatitude(), 41.15); assertEquals(li.getLongitude(), -8.617); }