@Test public void testQueryLocationWithPositiveGeoCoordinates() throws WeatherException { WeatherSource source = new OpenWeatherMapSource(context); Location location = new NameOpenWeatherMapLocation("55.0,73.4"); Weather weather = source.query(location); assertNotNull(weather); assertTrue(weather instanceof OpenWeatherMapWeather); assertFalse(weather.isEmpty()); assertEquals("Omsk", weather.getLocation().getText()); assertEquals(8, weather.getConditions().size()); }
@Override public Weather query(Location location) throws WeatherException { if (location == null) { throw new WeatherException("null location"); } if (!location.isGeo()) { try { if (location.getText().startsWith("-")) { return new TestWeather(Integer.parseInt(location.getText())); } if (location.getText().startsWith("+")) { return new TestWeather(Integer.parseInt(location.getText().substring(1))); } } catch (NumberFormatException nfe) { } } OpenWeatherMapWeather weather = new OpenWeatherMapWeather(this.context); weather.parseCurrentWeather(queryCurrentWeather(location)); if (weather.isEmpty()) { return weather; } if (weather.getLocation().isGeo()) { weather.parseOneCallResult(queryOneCallForecast(weather.getLocation())); } return weather; }
OpenWeatherMapSource extends HttpWeatherSource implements WeatherSource { @Override public Weather query(Location location) throws WeatherException { if (location == null) { throw new WeatherException("null location"); } if (!location.isGeo()) { try { if (location.getText().startsWith("-")) { return new TestWeather(Integer.parseInt(location.getText())); } if (location.getText().startsWith("+")) { return new TestWeather(Integer.parseInt(location.getText().substring(1))); } } catch (NumberFormatException nfe) { } } OpenWeatherMapWeather weather = new OpenWeatherMapWeather(this.context); weather.parseCurrentWeather(queryCurrentWeather(location)); if (weather.isEmpty()) { return weather; } if (weather.getLocation().isGeo()) { weather.parseOneCallResult(queryOneCallForecast(weather.getLocation())); } return weather; } }
OpenWeatherMapSource extends HttpWeatherSource implements WeatherSource { @Override public Weather query(Location location) throws WeatherException { if (location == null) { throw new WeatherException("null location"); } if (!location.isGeo()) { try { if (location.getText().startsWith("-")) { return new TestWeather(Integer.parseInt(location.getText())); } if (location.getText().startsWith("+")) { return new TestWeather(Integer.parseInt(location.getText().substring(1))); } } catch (NumberFormatException nfe) { } } OpenWeatherMapWeather weather = new OpenWeatherMapWeather(this.context); weather.parseCurrentWeather(queryCurrentWeather(location)); if (weather.isEmpty()) { return weather; } if (weather.getLocation().isGeo()) { weather.parseOneCallResult(queryOneCallForecast(weather.getLocation())); } return weather; } OpenWeatherMapSource(Context context); }
OpenWeatherMapSource extends HttpWeatherSource implements WeatherSource { @Override public Weather query(Location location) throws WeatherException { if (location == null) { throw new WeatherException("null location"); } if (!location.isGeo()) { try { if (location.getText().startsWith("-")) { return new TestWeather(Integer.parseInt(location.getText())); } if (location.getText().startsWith("+")) { return new TestWeather(Integer.parseInt(location.getText().substring(1))); } } catch (NumberFormatException nfe) { } } OpenWeatherMapWeather weather = new OpenWeatherMapWeather(this.context); weather.parseCurrentWeather(queryCurrentWeather(location)); if (weather.isEmpty()) { return weather; } if (weather.getLocation().isGeo()) { weather.parseOneCallResult(queryOneCallForecast(weather.getLocation())); } return weather; } OpenWeatherMapSource(Context context); @Override Weather query(Location location); @Override Weather query(Location location, Locale locale); }
OpenWeatherMapSource extends HttpWeatherSource implements WeatherSource { @Override public Weather query(Location location) throws WeatherException { if (location == null) { throw new WeatherException("null location"); } if (!location.isGeo()) { try { if (location.getText().startsWith("-")) { return new TestWeather(Integer.parseInt(location.getText())); } if (location.getText().startsWith("+")) { return new TestWeather(Integer.parseInt(location.getText().substring(1))); } } catch (NumberFormatException nfe) { } } OpenWeatherMapWeather weather = new OpenWeatherMapWeather(this.context); weather.parseCurrentWeather(queryCurrentWeather(location)); if (weather.isEmpty()) { return weather; } if (weather.getLocation().isGeo()) { weather.parseOneCallResult(queryOneCallForecast(weather.getLocation())); } return weather; } OpenWeatherMapSource(Context context); @Override Weather query(Location location); @Override Weather query(Location location, Locale locale);  }