### Question:
CityServiceImpl implements CityService { public Page<City> findCities(CitySearchCriteria criteria, Pageable pageable) { Assert.notNull(criteria, "Criteria must not be null"); String name = criteria.getName(); if (!StringUtils.hasLength(name)) { return this.cityRepository.findAll(null); } String country = ""; int splitPos = name.lastIndexOf(","); if (splitPos >= 0) { country = name.substring(splitPos + 1); name = name.substring(0, splitPos); } name = "%" + name.trim() + "%"; country = "%" + country.trim() + "%"; return this.cityRepository.findByNameLikeAndCountryLikeAllIgnoringCase(name, country, pageable); }  Page<City> findCities(CitySearchCriteria criteria, Pageable pageable); City getCity(String name, String country); Page<HotelSummary> getHotels(City city, Pageable pageable); @Autowired void setCityRepository(CityRepository ciryRepository); @Autowired void setHotelSummaryRepository(HotelSummaryRepository hotelSummaryRepository);  }### Answer:
@Test public void shouldFindCitiesByName() throws Exception { CitySearchCriteria criteria = new CitySearchCriteria("city"); given(this.cityRepository.findByNameLikeAndCountryLikeAllIgnoringCase("%city%", "%%", this.pageable)) .willReturn(this.cities); assertThat(this.cityService.findCities(criteria, this.pageable), is(this.cities)); }
@Test public void shouldFindCitiesByNameRestrictedToCountry() throws Exception { CitySearchCriteria criteria = new CitySearchCriteria("city, country"); given(this.cityRepository.findByNameLikeAndCountryLikeAllIgnoringCase("%city%", "%country%", this.pageable)) .willReturn(this.cities); assertThat(this.cityService.findCities(criteria, this.pageable), is(this.cities)); }
@Test public void shouldFindCitiesByNameRestrictedToCountryWithExtraCommas() throws Exception { CitySearchCriteria criteria = new CitySearchCriteria("ci,ty,country"); given(this.cityRepository.findByNameLikeAndCountryLikeAllIgnoringCase("%ci,ty%", "%country%", this.pageable)) .willReturn(this.cities); assertThat(this.cityService.findCities(criteria, this.pageable), is(this.cities)); }
@Test public void shouldFindCitiesByCountry() throws Exception { CitySearchCriteria criteria = new CitySearchCriteria(",country"); given(this.cityRepository.findByNameLikeAndCountryLikeAllIgnoringCase("%%", "%country%", this.pageable)) .willReturn(this.cities); assertThat(this.cityService.findCities(criteria, this.pageable), is(this.cities)); }