Refactoring. Checked old implementation.

This commit is contained in:
Alexey Zinchenko 2021-03-21 00:41:58 +03:00
parent 10ba59652b
commit d63de824b3
12 changed files with 514 additions and 45 deletions

View File

@ -20,8 +20,9 @@
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.request;
package com.github.prominence.openweathermap.api;
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequesterImpl;
public class OpenWeatherMapClient {
@ -32,7 +33,12 @@ public class OpenWeatherMapClient {
this.apiKey = apiKey;
}
public CurrentWeatherRequesterImpl currentWeather() {
public CurrentWeatherRequester currentWeather() {
return new CurrentWeatherRequesterImpl(apiKey);
}
// TODO:
// * Forecast: hourly, daily
// * Air Pollution
// * Ultraviolet index
}

View File

@ -60,7 +60,7 @@ public class CoordinateRectangle {
return latitudeTop;
}
public String getFormattedString() {
public String getFormattedRequestString() {
return longitudeLeft + "," + latitudeBottom + "," + longitudeRight + "," + latitudeTop;
}
@ -82,6 +82,6 @@ public class CoordinateRectangle {
@Override
public String toString() {
return "Rectangle: " + getFormattedString();
return "Rectangle: " + getFormattedRequestString();
}
}

View File

@ -22,6 +22,10 @@
package com.github.prominence.openweathermap.api.request;
import com.github.prominence.openweathermap.api.enums.Accuracy;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
@ -45,8 +49,16 @@ public class RequestUrlBuilder {
requestParameters.put(key, value);
}
public void setAPIKey(String key) {
requestParameters.put(API_KEY_PARAM_NAME, key);
public void applyCustomization(Accuracy accuracy, Language language, UnitSystem unitSystem) {
if (accuracy != null) {
addRequestParameter("type", accuracy.getValue());
}
if (language != null) {
addRequestParameter("lang", language.getValue());
}
if (unitSystem != null && unitSystem != UnitSystem.STANDARD) {
addRequestParameter("units", unitSystem.getValue());
}
}
public String buildUrl() {

View File

@ -36,7 +36,7 @@ public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLoc
@Override
public MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom) {
String coordinates = rectangle.getFormattedString() + "," + zoom;
String coordinates = rectangle.getFormattedRequestString() + "," + zoom;
urlBuilder.append("box/city");
urlBuilder.addRequestParameter("bbox", coordinates);
@ -45,7 +45,7 @@ public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLoc
@Override
public MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom, boolean useServerClustering) {
String coordinates = rectangle.getFormattedString() + "," + zoom;
String coordinates = rectangle.getFormattedRequestString() + "," + zoom;
urlBuilder.append("box/city");
urlBuilder.addRequestParameter("bbox", coordinates);
urlBuilder.addRequestParameter("cluster", useServerClustering ? "yes" : "no");

View File

@ -41,13 +41,13 @@ public class MultipleResultCurrentWeatherRequestCustomizerImpl implements Multip
@Override
public MultipleResultCurrentWeatherRequestTerminator retrieve() {
applyCustomization();
urlBuilder.applyCustomization(accuracy, language, unitSystem);
return new MultipleResultCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
}
@Override
public MultipleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
applyCustomization();
urlBuilder.applyCustomization(accuracy, language, unitSystem);
return new MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
}
@ -68,16 +68,4 @@ public class MultipleResultCurrentWeatherRequestCustomizerImpl implements Multip
this.unitSystem = unitSystem;
return this;
}
private void applyCustomization() {
if (accuracy != null) {
urlBuilder.addRequestParameter("type", accuracy.getValue());
}
if (language != null) {
urlBuilder.addRequestParameter("lang", language.getValue());
}
if (unitSystem != null && unitSystem != UnitSystem.STANDARD) {
urlBuilder.addRequestParameter("units", unitSystem.getValue());
}
}
}

View File

@ -34,28 +34,28 @@ public class SingleLocationCurrentWeatherRequesterImpl implements SingleLocation
urlBuilder.append("weather");
}
public SingleResultCurrentWeatherRequestCustomizerImpl byCityName(String cityName) {
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName) {
urlBuilder.addRequestParameter("q", cityName);
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
}
public SingleResultCurrentWeatherRequestCustomizerImpl byCityName(String cityName, String countryCode) {
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String countryCode) {
urlBuilder.addRequestParameter("q", cityName + "," + countryCode);
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
}
public SingleResultCurrentWeatherRequestCustomizerImpl byCityId(long cityId) {
public SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId) {
urlBuilder.addRequestParameter("id", cityId);
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
}
public SingleResultCurrentWeatherRequestCustomizerImpl byCoordinate(Coordinate coordinate) {
public SingleResultCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate) {
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
}
public SingleResultCurrentWeatherRequestCustomizerImpl byZipCodeAndCountry(String zipCode, String countryCode) {
public SingleResultCurrentWeatherRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
urlBuilder.addRequestParameter("zip", zipCode + "," + countryCode);
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
}

View File

@ -41,13 +41,13 @@ public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleRe
@Override
public SingleResultCurrentWeatherRequestTerminator retrieve() {
applyCustomization();
urlBuilder.applyCustomization(accuracy, language, unitSystem);
return new SingleResultCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
}
@Override
public SingleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
applyCustomization();
urlBuilder.applyCustomization(accuracy, language, unitSystem);
return new SingleResultCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
}
@ -68,16 +68,4 @@ public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleRe
this.unitSystem = unitSystem;
return this;
}
private void applyCustomization() {
if (accuracy != null) {
urlBuilder.addRequestParameter("type", accuracy.getValue());
}
if (language != null) {
urlBuilder.addRequestParameter("lang", language.getValue());
}
if (unitSystem != null && unitSystem != UnitSystem.STANDARD) {
urlBuilder.addRequestParameter("units", unitSystem.getValue());
}
}
}

View File

@ -124,5 +124,4 @@ public final class RequestUtils {
return result.toString();
}
}

View File

@ -22,7 +22,6 @@
package com.github.prominence.openweathermap.api;
import com.github.prominence.openweathermap.api.request.OpenWeatherMapClient;
import org.junit.BeforeClass;
public class ApiTest {

View File

@ -20,14 +20,15 @@
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api;
package com.github.prominence.openweathermap.api.request.weather;
import com.github.prominence.openweathermap.api.ApiTest;
import com.github.prominence.openweathermap.api.enums.Accuracy;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.request.OpenWeatherMapClient;
import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
import com.github.prominence.openweathermap.api.model.Weather;

View File

@ -0,0 +1,236 @@
/*
* Copyright (c) 2019 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.ApiTest;
import com.github.prominence.openweathermap.api.enums.Accuracy;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
import com.github.prominence.openweathermap.api.model.Weather;
import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
import org.junit.Test;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class CurrentWeatherIntegrationTest extends ApiTest {
@Test
public void whenGetMultipleCurrentWeatherByCoordinateRequestAsJava_thenReturnNotNull() {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byRectangle(new CoordinateRectangle(12, 32, 15, 37), 10)
.accuracy(Accuracy.ACCURATE)
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assert weatherList != null;
assert weatherList.size() > 0;
System.out.println(weatherList);
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringRequestAsJava_thenReturnNotNull() {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byRectangle(new CoordinateRectangle(12, 32, 15, 37), 10, true)
.accuracy(Accuracy.ACCURATE)
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assert weatherList != null;
assert weatherList.size() > 0;
System.out.println(weatherList);
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsJava_thenReturnNotNull() {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJava();
assert weatherList != null;
assert weatherList.size() > 0;
System.out.println(weatherList);
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleAndServerClusteringRequestAsJava_thenReturnNotNull() {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJava();
assert weatherList != null;
assert weatherList.size() > 0;
System.out.println(weatherList);
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsJson_thenReturnNotNull() {
final String weather = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJSON();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsXml_thenReturnNotNull() {
final String weather = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asXML();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsHtml_thenReturnNotNull() {
final String weather = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asHTML();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsJava_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<List<Weather>> weatherListFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
.asJava();
assert weatherListFuture != null;
List<Weather> weatherList = weatherListFuture.get();
assert weatherList.size() > 0;
System.out.println(weatherList);
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsXml_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
.asXML();
assert weatherFuture != null;
System.out.println(weatherFuture.get());
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsJson_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
.asJSON();
assert weatherFuture != null;
System.out.println(weatherFuture.get());
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsHtml_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
.asHTML();
assert weatherFuture != null;
System.out.println(weatherFuture.get());
}
@Test(expected = InvalidAuthTokenException.class)
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
client
.currentWeather()
.single()
.byCityName("London")
.retrieve()
.asJSON();
}
@Test(expected = NoDataFoundException.class)
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
getClient()
.currentWeather()
.single()
.byCityName("InvalidCity")
.retrieve()
.asJava();
}
}

View File

@ -0,0 +1,240 @@
/*
* Copyright (c) 2019 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.ApiTest;
import com.github.prominence.openweathermap.api.enums.Accuracy;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.Weather;
import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
import org.junit.Test;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class CurrentWeatherIntegrationTest extends ApiTest {
@Test
public void whenGetSingleCurrentWeatherByCoordinateRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byCoordinate(new Coordinate(5, 5))
.accuracy(Accuracy.ACCURATE)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetSingleCurrentWeatherByCityIdRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byCityId(350001514)
.language(Language.GERMAN)
.retrieve()
.asJava();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetSingleCurrentWeatherByCityNameRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byCityName("Minsk")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetSingleCurrentWeatherByCityNameAndCountryCodeRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byCityName("Moscow", "ru")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetSingleCurrentWeatherByZipCodeAndCountryRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetAnySingleCurrentRequestWeatherAsJson_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJSON();
assert weatherJson != null;
System.out.println(weatherJson);
}
@Test
public void whenGetAnySingleCurrentRequestWeatherAsXml_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asXML();
assert weatherXml != null;
System.out.println(weatherXml);
}
@Test
public void whenGetAnySingleCurrentWeatherRequestAsHtml_thenReturnNotNull() {
final String weatherHtml = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asHTML();
assert weatherHtml != null;
System.out.println(weatherHtml);
}
@Test
public void whenGetAnySingleCurrentWeatherAsyncRequestAsXml_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherXmlFuture = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
.asXML();
assert weatherXmlFuture != null;
System.out.println(weatherXmlFuture.get());
}
@Test
public void whenGetAnySingleCurrentWeatherAsyncRequestAsJava_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<Weather> weatherFuture = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
.asJava();
assert weatherFuture != null;
System.out.println(weatherFuture.get());
}
@Test
public void whenGetAnySingleCurrentWeatherAsyncRequestAsJson_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
.asJSON();
assert weatherFuture != null;
System.out.println(weatherFuture.get());
}
@Test
public void whenGetAnySingleCurrentWeatherAsyncRequestAsHtml_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
.asHTML();
assert weatherFuture != null;
System.out.println(weatherFuture.get());
}
@Test(expected = InvalidAuthTokenException.class)
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
client
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(34.53, 66.74), 10)
.retrieve()
.asJSON();
}
@Test(expected = NoDataFoundException.class)
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(90.00, 66.74), 10)
.retrieve()
.asJava();
}
}