mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-04 03:36:44 +03:00
Changed custom exceptions: now they are uncheked. Fixed several API issues. Added tests.
This commit is contained in:
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.OpenWeatherMapManager;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class ApiTest {
|
||||
|
||||
private static OpenWeatherMapManager manager;
|
||||
|
||||
@BeforeClass
|
||||
public static void retrieveApiKey() {
|
||||
String apiKey = System.getenv("OPENWEATHER_API_KEY");
|
||||
manager = new OpenWeatherMapManager(apiKey);
|
||||
}
|
||||
|
||||
protected static OpenWeatherMapManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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