GeoNamesCityRepository implements CityRepository { @Override public Page<City> searchCity(String term, Pageable pageable) { return searchCity(term, null, null, pageable); } GeoNamesCityRepository(final Set<String> upExcludedCountryCodes, CountryRepository countryRepo);  GeoNamesCityRepository(CountryRepository countryRepo); @Override @Nullable City getCity(String countryCodeNormalizedProvinceAndName); @Override String getKeyForCity(City city); @Override City getCity(String name, @Nullable String province, String countryCode); @Override Country getCountry(String iso2orIso3); @Override Page<City> searchCity(String term, Pageable pageable); @Override Page<City> searchCity(String term, String province, Pageable pageable); @Override Page<City> searchCity(String term, @Nullable String province, @Nullable String countryIso, Pageable pageable); @Override City putCity(String name, String normalizedName, String countryCode, @Nullable String provinceName); void putCitiesFromDistrictTsv(final String countryIso, URL url); @Override long count(); static final String CITIES1000LITE_CSV; }
@Test public void searchCityIndr() { final String term = "iNdR"; final Page<City> cities1 = cityRepo.searchCity(term, new PageRequest(0, 5)); log.info("Search {}: {}", term, cities1); final Page<City> cities2 = cityRepo.searchCity(term, new PageRequest(1, 5)); log.info("Search {}: {}", term, cities2); assertEquals(5, cities1.getNumberOfElements()); assertEquals(7, cities1.getTotalElements()); assertEquals(2, cities2.getNumberOfElements()); assertEquals(7, cities2.getTotalElements()); }
@Test public void searchCityWates() { final String term = "wates"; final Page<City> cities1 = cityRepo.searchCity(term, new PageRequest(0, 5)); log.info("Search {}: {}", term, cities1); final Page<City> cities2 = cityRepo.searchCity(term, new PageRequest(1, 5)); log.info("Search {}: {}", term, cities2); assertEquals(1, cities1.getNumberOfElements()); assertEquals(1, cities1.getTotalElements()); assertEquals(0, cities2.getNumberOfElements()); assertEquals(1, cities2.getTotalElements()); }
@Test public void searchCityIndrExcluded() throws IOException { final CityRepository cityRepo = new GeoNamesCityRepository(ImmutableSet.of("ID"), null); final String term = "iNdR"; final Page<City> cities1 = cityRepo.searchCity(term, new PageRequest(0, 5)); log.info("Search {}: {}", term, cities1); final Page<City> cities2 = cityRepo.searchCity(term, new PageRequest(1, 5)); log.info("Search {}: {}", term, cities2); assertEquals(3, cities1.getNumberOfElements()); assertEquals(3, cities1.getTotalElements()); assertEquals(0, cities2.getNumberOfElements()); assertEquals(3, cities2.getTotalElements()); }