OpenWeatherClient extends BaseRetrofitClient implements CleanRepository { public List<City> getCities(Double latitude, Double longitude, Integer count) { try { OpenWeatherWrapper openWeatherWrapper = openWeatherAPI.getWeatherItems(latitude, longitude, count); return openWeatherResponseMapper.mapResponse(openWeatherWrapper); } catch (Exception exception) { return throwGetCitiesException(exception); } }  void getCitiesAsync(final Double latitude, final Double longitude, final Integer count); List<City> getCities(Double latitude, Double longitude, Integer count); static String ENDPOINT; }
@Test public void testWeatherClient() throws Exception { mockWebServer.enqueue(new MockResponse().setHeader("Server", "mockwebserver").setBody(TestHelper.getStringFromResource("openweatherresponse.txt"))); List<City> cities = openWeatherClient.getCities(AppConfig.TEST_DATA.BP_LATITUDE, AppConfig.TEST_DATA.BP_LONGITUDE, 25); assertThat(openWeatherClient).isNotNull(); assertThat(cities).isNotEmpty(); TestHelper.printCollection(cities); }
@Test public void testWeatherClientWithRetry() throws Exception { mockWebServer.enqueue(new MockResponse().setHeader("Server", "mockwebserver") .setResponseCode(403)); mockWebServer.enqueue(new MockResponse().setHeader("Server", "mockwebserver").setBody(TestHelper.getStringFromResource("openweatherresponse.txt"))); List<City> cities = openWeatherClient.getCities(AppConfig.TEST_DATA.BP_LATITUDE, AppConfig.TEST_DATA.BP_LONGITUDE, 25); assertThat(openWeatherClient).isNotNull(); assertThat(cities).isNotEmpty(); TestHelper.printCollection(cities); }
@Test(expected = GetCitiesException.class) public void testWeatherClientWithConnectionError() throws Exception { mockWebServer.enqueue(new MockResponse().setHeader("Server", "mockwebserver") .setResponseCode(403)); mockWebServer.enqueue(new MockResponse().setHeader("Server", "mockwebserver") .setResponseCode(403)); List<City> cities = openWeatherClient.getCities(AppConfig.TEST_DATA.BP_LATITUDE, AppConfig.TEST_DATA.BP_LONGITUDE, 25); }