mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-04 03:36:44 +03:00
Added new draft current weather retrieving implementation.
This commit is contained in:
-51
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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.test;
|
||||
|
||||
import com.github.prominence.openweathermap.api.AirPollutionRequester;
|
||||
import com.github.prominence.openweathermap.api.constants.TimeFrame;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class AirPollutionRequestedIntegrationTest extends ApiTest {
|
||||
|
||||
private static AirPollutionRequester airPollutionRequester;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
airPollutionRequester = getManager().getAirPollutionRequester(0f, 10f, new Date(116, 11, 25), TimeFrame.DAY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestAirPollutionState_thenReturnNotNull() {
|
||||
assert airPollutionRequester.retrieve() != null;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenRequestAirPollutionStateWithoutAnyParam_thenThrowAnException() {
|
||||
AirPollutionRequester requester = getManager().getAirPollutionRequester(0f, 10f, null, TimeFrame.DAY);
|
||||
requester.retrieve();
|
||||
}
|
||||
}
|
||||
@@ -22,20 +22,20 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.test;
|
||||
|
||||
import com.github.prominence.openweathermap.api.OpenWeatherMapManager;
|
||||
import com.github.prominence.openweathermap.api.impl.OpenWeatherMapClient;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class ApiTest {
|
||||
|
||||
private static OpenWeatherMapManager manager;
|
||||
private static OpenWeatherMapClient manager;
|
||||
|
||||
@BeforeClass
|
||||
public static void retrieveApiKey() {
|
||||
String apiKey = System.getenv("OPENWEATHER_API_KEY");
|
||||
manager = new OpenWeatherMapManager(apiKey);
|
||||
manager = new OpenWeatherMapClient(apiKey);
|
||||
}
|
||||
|
||||
protected static OpenWeatherMapManager getManager() {
|
||||
protected static OpenWeatherMapClient getClient() {
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
|
||||
+332
@@ -0,0 +1,332 @@
|
||||
/*
|
||||
* 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.test;
|
||||
|
||||
import com.github.prominence.openweathermap.api.enums.Accuracy;
|
||||
import com.github.prominence.openweathermap.api.enums.Language;
|
||||
import com.github.prominence.openweathermap.api.enums.Unit;
|
||||
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 org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
|
||||
@Test
|
||||
public void whenGetSingleCurrentWeatherByCoordinateRequestAsJava_thenReturnNotNull() {
|
||||
final Weather weather = getClient()
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCoordinate(new Coordinate(5, 5))
|
||||
.accuracy(Accuracy.ACCURATE)
|
||||
.language(Language.ROMANIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asHTML();
|
||||
|
||||
assert weatherHtml != null;
|
||||
System.out.println(weatherHtml);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetAnySingleCurrentWeatherAsyncRequestAsXml_thenReturnNotNull() {
|
||||
final CompletableFuture<String> weatherXmlFuture = getClient()
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
|
||||
assert weatherXmlFuture != null;
|
||||
weatherXmlFuture.thenAccept(System.out::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetAnySingleCurrentWeatherAsyncRequestAsJava_thenReturnNotNull() {
|
||||
final CompletableFuture<Weather> weatherFuture = getClient()
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assert weatherFuture != null;
|
||||
weatherFuture.thenAccept(System.out::println);
|
||||
}
|
||||
|
||||
@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)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.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)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asHTML();
|
||||
|
||||
assert weather != null;
|
||||
System.out.println(weather);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsJava_thenReturnNotNull() {
|
||||
final CompletableFuture<List<Weather>> weatherListFuture = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assert weatherListFuture != null;
|
||||
weatherListFuture.thenAccept(result -> {
|
||||
assert result.size() > 0;
|
||||
System.out.println(result);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsXml_thenReturnNotNull() {
|
||||
final CompletableFuture<String> weatherFuture = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
|
||||
assert weatherFuture != null;
|
||||
weatherFuture.thenAccept(System.out::println);
|
||||
}
|
||||
}
|
||||
-101
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* 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.test;
|
||||
|
||||
import com.github.prominence.openweathermap.api.HourlyForecastRequester;
|
||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HourlyForecastRequesterIntegrationTest extends ApiTest {
|
||||
|
||||
private static HourlyForecastRequester hourlyForecastRequester;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
hourlyForecastRequester = getManager().getHourlyForecastRequester();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestForecastForMinskByCity() {
|
||||
assert hourlyForecastRequester.getByCityName("Minsk") != null;
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenRequestForecastByWrongCity_thenThrowAnException() {
|
||||
hourlyForecastRequester.getByCityId("IncorrectCity");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestForecastForMinskById_thenReturnNotNull() {
|
||||
assert hourlyForecastRequester.getByCityId("625144") != null;
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenRequestForecastByWrongId_thenThrowAnException() {
|
||||
hourlyForecastRequester.getByCityId("IncorrectId");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestForecastByCoordinates_thenReturnNotNull() {
|
||||
// given
|
||||
float latitude = 53.9f;
|
||||
float longitude = 27.56667f;
|
||||
Coordinates coordinates = new Coordinates(latitude, longitude);
|
||||
|
||||
// expected
|
||||
assert hourlyForecastRequester.getByCoordinates(coordinates) != null;
|
||||
assert hourlyForecastRequester.getByCoordinates(latitude, longitude) != null;
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class) // not good, will be reimplemented in further versions
|
||||
public void whenRequestByNullCoordinates_thenThrowAnException() {
|
||||
hourlyForecastRequester.getByCoordinates(null);
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenRequestForecastByWrongCoordinates_thenThrowAnException() {
|
||||
hourlyForecastRequester.getByCoordinates(91f, 180f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestForecastByMaxCoordinates_thenReturnNotNull() {
|
||||
assert hourlyForecastRequester.getByCoordinates(90f, 180f) != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestForecastByMinCoordinates_thenReturnNotNull() {
|
||||
assert hourlyForecastRequester.getByCoordinates(-90f, -180f) != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestForecastByZipCode_thenReturnNotNull() {
|
||||
assert hourlyForecastRequester.getByZIPCode("220015", "BY") != null;
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenRequestForecastByWrongZipCode_thenThrowAnException() {
|
||||
hourlyForecastRequester.getByZIPCode("wrongZipCode", "BY");
|
||||
}
|
||||
}
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* 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.test;
|
||||
|
||||
import com.github.prominence.openweathermap.api.UltravioletIndexRequester;
|
||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class UltravioletIndexRequestedIntegrationTest extends ApiTest {
|
||||
|
||||
private static UltravioletIndexRequester minskUltravioletIndexRequester;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
minskUltravioletIndexRequester = getManager().getUltravioletIndexRequester(53.9f, 27.56667f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestUVI_thenReturnNotNull() {
|
||||
assert minskUltravioletIndexRequester.getCurrentUVIndex() != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestUVIForecastFor5Days_thenReturnNotNull() {
|
||||
assert minskUltravioletIndexRequester.getUVIndexForecast(5) != null;
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenRequestUVIForecastForWrongAmountOfDays_thenThrowAnException() {
|
||||
minskUltravioletIndexRequester.getUVIndexForecast(-2);
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenRequestUVIForecastForLargeAmountOfDays_thenThrowAnException() {
|
||||
assert minskUltravioletIndexRequester.getUVIndexForecast(10000) != null;
|
||||
}
|
||||
|
||||
@Test // check it later
|
||||
public void whenRequestUVIForPeriod_thenReturnNotNull() {
|
||||
assert minskUltravioletIndexRequester.getUVIndexByPeriod(new Date(), new Date()) != null;
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class) // not good, will be reimplemented in further versions
|
||||
public void whenRequestUVIForNullPeriod_thenThrowAnException() {
|
||||
minskUltravioletIndexRequester.getUVIndexByPeriod(null, null);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class) // not good, will be reimplemented in further versions
|
||||
public void whenRequestUVIForNullCoordinates_thenThrowAnException() {
|
||||
UltravioletIndexRequester requester = getManager().getUltravioletIndexRequester(null);
|
||||
requester.getCurrentUVIndex();
|
||||
}
|
||||
}
|
||||
-101
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* 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.test;
|
||||
|
||||
import com.github.prominence.openweathermap.api.WeatherRequester;
|
||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class WeatherRequestIntegrationTest extends ApiTest {
|
||||
|
||||
private static WeatherRequester weatherRequester;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
weatherRequester = getManager().getWeatherRequester();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestWeatherForMinskByName_thenReturnNotNull() {
|
||||
assert weatherRequester.getByCityName("Minsk") != null;
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenRequestWeatherByWrongCity_thenThrowAnException() {
|
||||
weatherRequester.getByCityId("IncorrectCity");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestWeatherForMinskById_thenReturnNotNull() {
|
||||
assert weatherRequester.getByCityId("625144") != null;
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenRequestWeatherByWrongId_thenThrowAnException() {
|
||||
weatherRequester.getByCityId("IncorrectId");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestWeatherByCoordinates_thenReturnNotNull() {
|
||||
// given
|
||||
float latitude = 53.9f;
|
||||
float longitude = 27.56667f;
|
||||
Coordinates coordinates = new Coordinates(latitude, longitude);
|
||||
|
||||
// expected
|
||||
assert weatherRequester.getByCoordinates(coordinates) != null;
|
||||
assert weatherRequester.getByCoordinates(latitude, longitude) != null;
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class) // not good, will be reimplemented in further versions
|
||||
public void whenRequestByNullCoordinates_thenThrowAnException() {
|
||||
weatherRequester.getByCoordinates(null);
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenRequestWeatherByWrongCoordinates_thenThrowAnException() {
|
||||
weatherRequester.getByCoordinates(91f, 180f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestWeatherByMaxCoordinates_thenReturnNotNull() {
|
||||
assert weatherRequester.getByCoordinates(90f, 180f) != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestWeatherByMinCoordinates_thenReturnNotNull() {
|
||||
assert weatherRequester.getByCoordinates(-90f, -180f) != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestWeatherByZipCode_thenReturnNotNull() {
|
||||
assert weatherRequester.getByZIPCode("220015", "BY") != null;
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenRequestWeatherByWrongZipCode_thenThrowAnException() {
|
||||
weatherRequester.getByZIPCode("wrongZipCode", "BY");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user