mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-09 19:46:41 +03:00
Added draft unit tests for model to cover all lines.
This commit is contained in:
parent
dbc5b08f43
commit
d3ca16472b
@ -258,9 +258,9 @@ Available requests:
|
||||
| `getHumidity()` | Returns *humidity* percentage information. |
|
||||
| `getWindSpeed()` | Returns wind's speed. |
|
||||
| `getWindDegrees()` | Returns wind's degree. |
|
||||
| `getWindUnit()` | Returns wind's unit. |
|
||||
| `getWindUnit()` | Returns wind's unitSystem. |
|
||||
| `getPressure()` | Returns pressure value. |
|
||||
| `getPressureUnit()` | Returns pressure's unit. |
|
||||
| `getPressureUnit()` | Returns pressure's unitSystem. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
#### UV Index
|
||||
|
||||
@ -258,9 +258,9 @@ Available requests:
|
||||
| `getHumidity()` | Returns *humidity* percentage information. |
|
||||
| `getWindSpeed()` | Returns wind's speed. |
|
||||
| `getWindDegrees()` | Returns wind's degree. |
|
||||
| `getWindUnit()` | Returns wind's unit. |
|
||||
| `getWindUnit()` | Returns wind's unitSystem. |
|
||||
| `getPressure()` | Returns pressure value. |
|
||||
| `getPressureUnit()` | Returns pressure's unit. |
|
||||
| `getPressureUnit()` | Returns pressure's unitSystem. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
#### UV Index
|
||||
|
||||
@ -31,9 +31,9 @@ openWeatherClient
|
||||
.currentWeather()
|
||||
.<single|multiple location(s)>()
|
||||
.<location definition>
|
||||
.<customize unit/language/accuracy (1)>
|
||||
.<customize unitSystem/language/accuracy (1)>
|
||||
...
|
||||
.<customize unit/language/accuracy (N)>
|
||||
.<customize unitSystem/language/accuracy (N)>
|
||||
.<request/requestAsync>()
|
||||
.as(Java|JSON|XML|HTML)();
|
||||
```
|
||||
@ -59,7 +59,7 @@ final Weather weather = openWeatherClient
|
||||
.byCoordinate(new Coordinate(5, 5))
|
||||
.accuracy(Accuracy.ACCURATE)
|
||||
.language(Language.ROMANIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(Unit.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@ -68,7 +68,7 @@ final CompletableFuture<String> weatherXmlFuture = openWeatherClient
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(Unit.METRIC_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
```
|
||||
@ -81,7 +81,7 @@ final String weatherListJson = openWeatherClient
|
||||
.byRectangle(new CoordinateRectangle(12, 32, 15, 37), 10, true)
|
||||
.accuracy(Accuracy.ACCURATE)
|
||||
.language(Language.ROMANIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(Unit.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
@ -89,7 +89,7 @@ final CompletableFuture<List<Weather>> weatherListFuture = openWeatherClient
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(Unit.IMPERIAL_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
@ -24,7 +24,7 @@ package com.github.prominence.openweathermap.api;
|
||||
|
||||
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.enums.UnitSystem;
|
||||
|
||||
public interface RequestCustomizer<T extends RequestCustomizer<?>> {
|
||||
|
||||
@ -32,5 +32,5 @@ public interface RequestCustomizer<T extends RequestCustomizer<?>> {
|
||||
|
||||
T language(Language language);
|
||||
|
||||
T unit(Unit unit);
|
||||
T unitSystem(UnitSystem unitSystem);
|
||||
}
|
||||
|
||||
@ -1,42 +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.enums;
|
||||
|
||||
public enum ResponseType {
|
||||
|
||||
JAVA_OBJECT("java)"),
|
||||
JSON("json"),
|
||||
XML("xml"),
|
||||
HTML("html"),
|
||||
RAW("raw");
|
||||
|
||||
private final String value;
|
||||
|
||||
ResponseType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.enums;
|
||||
|
||||
public enum Unit {
|
||||
public enum UnitSystem {
|
||||
|
||||
METRIC_SYSTEM("metric"),
|
||||
IMPERIAL_SYSTEM("imperial"),
|
||||
@ -30,11 +30,11 @@ public enum Unit {
|
||||
|
||||
private final String value;
|
||||
|
||||
Unit(String value) {
|
||||
UnitSystem(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static String getWindUnit(Unit type) {
|
||||
public static String getWindUnit(UnitSystem type) {
|
||||
switch (type) {
|
||||
case IMPERIAL_SYSTEM:
|
||||
return "miles/hour";
|
||||
@ -45,7 +45,7 @@ public enum Unit {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTemperatureUnit(Unit type) {
|
||||
public static String getTemperatureUnit(UnitSystem type) {
|
||||
switch (type) {
|
||||
case METRIC_SYSTEM:
|
||||
return "℃";
|
||||
@ -25,7 +25,7 @@ package com.github.prominence.openweathermap.api.impl;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.prominence.openweathermap.api.ResponseMapper;
|
||||
import com.github.prominence.openweathermap.api.enums.Unit;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.model.*;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -40,51 +40,51 @@ import java.util.TimeZone;
|
||||
* Official API response documentation:
|
||||
* Parameters:
|
||||
* --- coord
|
||||
* |- coord.lon City geo location, longitude
|
||||
* |- coord.lat City geo location, latitude
|
||||
* |- coord.lon City geo location, longitude
|
||||
* |- coord.lat City geo location, latitude
|
||||
* --- weather (more info Weather condition codes)
|
||||
* |- weather.id Weather condition id
|
||||
* |- weather.main Group of weather parameters (Rain, Snow, Extreme etc.)
|
||||
* |- weather.description Weather condition within the group
|
||||
* |- weather.icon Weather icon id
|
||||
* |- weather.id Weather condition id
|
||||
* |- weather.main Group of weather parameters (Rain, Snow, Extreme etc.)
|
||||
* |- weather.description Weather condition within the group
|
||||
* |- weather.icon Weather icon id
|
||||
* --- base Internal parameter
|
||||
* --- main
|
||||
* |- main.temp Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||
* |- main.pressure Atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), hPa
|
||||
* |- main.humidity Humidity, %
|
||||
* |- main.temp_min Minimum temperature at the moment. This is deviation from current temp that is possible for large cities and megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||
* |- main.temp_max Maximum temperature at the moment. This is deviation from current temp that is possible for large cities and megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||
* |- main.sea_level Atmospheric pressure on the sea level, hPa
|
||||
* |- main.grnd_level Atmospheric pressure on the ground level, hPa
|
||||
* |- main.temp Temperature. UnitSystem Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||
* |- main.pressure Atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), hPa
|
||||
* |- main.humidity Humidity, %
|
||||
* |- main.temp_min Minimum temperature at the moment. This is deviation from current temp that is possible for large cities and megalopolises geographically expanded (use these parameter optionally). UnitSystem Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||
* |- main.temp_max Maximum temperature at the moment. This is deviation from current temp that is possible for large cities and megalopolises geographically expanded (use these parameter optionally). UnitSystem Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||
* |- main.sea_level Atmospheric pressure on the sea level, hPa
|
||||
* |- main.grnd_level Atmospheric pressure on the ground level, hPa
|
||||
* --- wind
|
||||
* |- wind.speed Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
|
||||
* |- wind.deg Wind direction, degrees (meteorological)
|
||||
* |- wind.speed Wind speed. UnitSystem Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
|
||||
* |- wind.deg Wind direction, degrees (meteorological)
|
||||
* --- clouds
|
||||
* |- clouds.all Cloudiness, %
|
||||
* |- clouds.all Cloudiness, %
|
||||
* --- rain
|
||||
* |- rain.1h Rain volume for the last 1 hour, mm
|
||||
* |- rain.3h Rain volume for the last 3 hours, mm
|
||||
* |- rain.1h Rain volume for the last 1 hour, mm
|
||||
* |- rain.3h Rain volume for the last 3 hours, mm
|
||||
* --- snow
|
||||
* |- snow.1h Snow volume for the last 1 hour, mm
|
||||
* |- snow.3h Snow volume for the last 3 hours, mm
|
||||
* |- snow.1h Snow volume for the last 1 hour, mm
|
||||
* |- snow.3h Snow volume for the last 3 hours, mm
|
||||
* --- dt Time of data calculation, unix, UTC
|
||||
* --- sys
|
||||
* |- sys.type Internal parameter
|
||||
* |- sys.id Internal parameter
|
||||
* |- sys.message Internal parameter
|
||||
* |- sys.country Country code (GB, JP etc.)
|
||||
* |- sys.sunrise Sunrise time, unix, UTC
|
||||
* |- sys.sunset Sunset time, unix, UTC
|
||||
* |- sys.type Internal parameter
|
||||
* |- sys.id Internal parameter
|
||||
* |- sys.message Internal parameter
|
||||
* |- sys.country Country code (GB, JP etc.)
|
||||
* |- sys.sunrise Sunrise time, unix, UTC
|
||||
* |- sys.sunset Sunset time, unix, UTC
|
||||
* --- id City ID
|
||||
* --- name City name
|
||||
* --- cod Internal parameter
|
||||
*/
|
||||
public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
|
||||
|
||||
private Unit unit;
|
||||
private UnitSystem unitSystem;
|
||||
|
||||
CurrentWeatherResponseMapper(Unit unit) {
|
||||
this.unit = unit != null ? unit : Unit.STANDARD_SYSTEM;
|
||||
CurrentWeatherResponseMapper(UnitSystem unitSystem) {
|
||||
this.unitSystem = unitSystem != null ? unitSystem : UnitSystem.STANDARD_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,11 +102,10 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
|
||||
}
|
||||
|
||||
private Weather getSingle(JsonNode root) {
|
||||
final Weather weather = new Weather();
|
||||
final Weather weather;
|
||||
|
||||
JsonNode weatherState = root.get("weather").get(0);
|
||||
weather.setWeatherState(weatherState.get("main").asText());
|
||||
weather.setWeatherDescription(weatherState.get("description").asText());
|
||||
weather = new Weather(weatherState.get("main").asText(), weatherState.get("description").asText());
|
||||
weather.setWeatherIconUrl("http://openweathermap.org/img/w/" + weatherState.get("icon").asText() + ".png");
|
||||
|
||||
weather.setTemperature(parseTemperature(root));
|
||||
@ -142,28 +141,26 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
|
||||
}
|
||||
|
||||
private Temperature parseTemperature(JsonNode root) {
|
||||
Temperature temperature = new Temperature();
|
||||
Temperature temperature;
|
||||
final JsonNode mainNode = root.get("main");
|
||||
|
||||
temperature.setValue(mainNode.get("temp").asDouble());
|
||||
final double tempValue = mainNode.get("temp").asDouble();
|
||||
temperature = new Temperature(tempValue, UnitSystem.getTemperatureUnit(unitSystem));
|
||||
final JsonNode tempMaxNode = mainNode.get("temp_max");
|
||||
final JsonNode tempMinNode = mainNode.get("temp_min");
|
||||
if (tempMaxNode != null) {
|
||||
temperature.setMaxTemperature(tempMaxNode.asDouble());
|
||||
}
|
||||
final JsonNode tempMinNode = mainNode.get("temp_min");
|
||||
if (tempMinNode != null) {
|
||||
temperature.setMinTemperature(tempMinNode.asDouble());
|
||||
}
|
||||
temperature.setUnit(Unit.getTemperatureUnit(unit));
|
||||
|
||||
return temperature;
|
||||
}
|
||||
|
||||
private Pressure parsePressure(JsonNode root) {
|
||||
Pressure pressure = new Pressure();
|
||||
|
||||
final JsonNode mainNode = root.get("main");
|
||||
pressure.setValue(mainNode.get("pressure").asDouble());
|
||||
Pressure pressure = new Pressure(mainNode.get("pressure").asDouble());
|
||||
|
||||
final JsonNode seaLevelNode = mainNode.get("sea_level");
|
||||
final JsonNode grndLevelNode = mainNode.get("grnd_level");
|
||||
@ -178,24 +175,20 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
|
||||
}
|
||||
|
||||
private Humidity parseHumidity(JsonNode root) {
|
||||
Humidity humidity = new Humidity();
|
||||
|
||||
final JsonNode mainNode = root.get("main");
|
||||
humidity.setValue(mainNode.get("humidity").asInt());
|
||||
|
||||
return humidity;
|
||||
return new Humidity((byte) (mainNode.get("humidity").asInt()));
|
||||
}
|
||||
|
||||
private Wind parseWind(JsonNode root) {
|
||||
Wind wind = new Wind();
|
||||
final JsonNode windNode = root.get("wind");
|
||||
double speed = windNode.get("speed").asDouble();
|
||||
|
||||
wind.setSpeed(windNode.get("speed").asDouble());
|
||||
Wind wind = new Wind(speed, UnitSystem.getWindUnit(unitSystem));
|
||||
final JsonNode degNode = windNode.get("deg");
|
||||
if (degNode != null) {
|
||||
wind.setDegrees(degNode.asDouble());
|
||||
}
|
||||
wind.setUnit(Unit.getWindUnit(unit));
|
||||
|
||||
return wind;
|
||||
}
|
||||
@ -240,22 +233,19 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
|
||||
}
|
||||
|
||||
private Clouds parseClouds(JsonNode root) {
|
||||
Clouds clouds = new Clouds();
|
||||
Clouds clouds = null;
|
||||
|
||||
final JsonNode cloudsNode = root.get("clouds");
|
||||
final JsonNode allValueNode = cloudsNode.get("all");
|
||||
if (allValueNode != null) {
|
||||
clouds.setValue((byte) allValueNode.asInt());
|
||||
clouds = new Clouds((byte) allValueNode.asInt());
|
||||
}
|
||||
|
||||
return clouds;
|
||||
}
|
||||
|
||||
private Location parseLocation(JsonNode root) {
|
||||
Location location = new Location();
|
||||
|
||||
location.setName(root.get("name").asText());
|
||||
location.setId(root.get("id").asInt());
|
||||
Location location = new Location(root.get("id").asInt(), root.get("name").asText());
|
||||
|
||||
final JsonNode timezoneNode = root.get("timezone");
|
||||
if (timezoneNode != null) {
|
||||
|
||||
@ -37,7 +37,7 @@ public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLoc
|
||||
|
||||
@Override
|
||||
public MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom) {
|
||||
String coordinates = rectangle.getValue() + "," + zoom;
|
||||
String coordinates = rectangle.getFormattedString() + "," + zoom;
|
||||
urlBuilder.append("box/city");
|
||||
urlBuilder.addRequestParameter("bbox", coordinates);
|
||||
|
||||
@ -46,7 +46,7 @@ public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLoc
|
||||
|
||||
@Override
|
||||
public MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom, boolean useServerClustering) {
|
||||
String coordinates = rectangle.getValue() + "," + zoom;
|
||||
String coordinates = rectangle.getFormattedString() + "," + zoom;
|
||||
urlBuilder.append("box/city");
|
||||
urlBuilder.addRequestParameter("bbox", coordinates);
|
||||
urlBuilder.addRequestParameter("cluster", useServerClustering ? "yes" : "no");
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
|
||||
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherAsyncRequestTerminator;
|
||||
import com.github.prominence.openweathermap.api.enums.Unit;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
|
||||
@ -33,16 +33,16 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class MultipleResultCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCurrentWeatherAsyncRequestTerminator {
|
||||
|
||||
private RequestUrlBuilder urlBuilder;
|
||||
private Unit unit;
|
||||
private UnitSystem unitSystem;
|
||||
|
||||
MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, Unit unit) {
|
||||
MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
this.unit = unit;
|
||||
this.unitSystem = unitSystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<Weather>> asJava() {
|
||||
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unit).getList(getRawResponse()));
|
||||
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -27,7 +27,7 @@ import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherRequ
|
||||
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherRequestTerminator;
|
||||
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.enums.UnitSystem;
|
||||
|
||||
public class MultipleResultCurrentWeatherRequestCustomizerImpl implements MultipleResultCurrentWeatherRequestCustomizer {
|
||||
|
||||
@ -35,7 +35,7 @@ public class MultipleResultCurrentWeatherRequestCustomizerImpl implements Multip
|
||||
|
||||
private Accuracy accuracy;
|
||||
private Language language;
|
||||
private Unit unit;
|
||||
private UnitSystem unitSystem;
|
||||
|
||||
MultipleResultCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
@ -44,13 +44,13 @@ public class MultipleResultCurrentWeatherRequestCustomizerImpl implements Multip
|
||||
@Override
|
||||
public MultipleResultCurrentWeatherRequestTerminator retrieve() {
|
||||
applyCustomization();
|
||||
return new MultipleResultCurrentWeatherRequestTerminatorImpl(urlBuilder, unit);
|
||||
return new MultipleResultCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultipleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||
applyCustomization();
|
||||
return new MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unit);
|
||||
return new MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,8 +66,8 @@ public class MultipleResultCurrentWeatherRequestCustomizerImpl implements Multip
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultipleResultCurrentWeatherRequestCustomizer unit(Unit unit) {
|
||||
this.unit = unit;
|
||||
public MultipleResultCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||
this.unitSystem = unitSystem;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -78,8 +78,8 @@ public class MultipleResultCurrentWeatherRequestCustomizerImpl implements Multip
|
||||
if (language != null) {
|
||||
urlBuilder.addRequestParameter("lang", language.getValue());
|
||||
}
|
||||
if (unit != null && unit != Unit.STANDARD_SYSTEM) {
|
||||
urlBuilder.addRequestParameter("units", unit.getValue());
|
||||
if (unitSystem != null && unitSystem != UnitSystem.STANDARD_SYSTEM) {
|
||||
urlBuilder.addRequestParameter("units", unitSystem.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,7 +23,7 @@
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
|
||||
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherRequestTerminator;
|
||||
import com.github.prominence.openweathermap.api.enums.Unit;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
|
||||
@ -32,16 +32,16 @@ import java.util.List;
|
||||
public class MultipleResultCurrentWeatherRequestTerminatorImpl implements MultipleResultCurrentWeatherRequestTerminator {
|
||||
|
||||
private RequestUrlBuilder urlBuilder;
|
||||
private Unit unit;
|
||||
private UnitSystem unitSystem;
|
||||
|
||||
MultipleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, Unit unit) {
|
||||
MultipleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
this.unit = unit;
|
||||
this.unitSystem = unitSystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Weather> asJava() {
|
||||
return new CurrentWeatherResponseMapper(unit).getList(getRawResponse());
|
||||
return new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
|
||||
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherAsyncRequestTerminator;
|
||||
import com.github.prominence.openweathermap.api.enums.Unit;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
|
||||
@ -32,16 +32,16 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class SingleResultCurrentWeatherAsyncRequestTerminatorImpl implements SingleResultCurrentWeatherAsyncRequestTerminator {
|
||||
|
||||
private RequestUrlBuilder urlBuilder;
|
||||
private Unit unit;
|
||||
private UnitSystem unitSystem;
|
||||
|
||||
SingleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, Unit unit) {
|
||||
SingleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
this.unit = unit;
|
||||
this.unitSystem = unitSystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Weather> asJava() {
|
||||
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unit).getSingle(getRawResponse()));
|
||||
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getSingle(getRawResponse()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -27,7 +27,7 @@ import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherReques
|
||||
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherRequestTerminator;
|
||||
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.enums.UnitSystem;
|
||||
|
||||
public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleResultCurrentWeatherRequestCustomizer {
|
||||
|
||||
@ -35,7 +35,7 @@ public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleRe
|
||||
|
||||
private Accuracy accuracy;
|
||||
private Language language;
|
||||
private Unit unit;
|
||||
private UnitSystem unitSystem;
|
||||
|
||||
SingleResultCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
@ -44,13 +44,13 @@ public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleRe
|
||||
@Override
|
||||
public SingleResultCurrentWeatherRequestTerminator retrieve() {
|
||||
applyCustomization();
|
||||
return new SingleResultCurrentWeatherRequestTerminatorImpl(urlBuilder, unit);
|
||||
return new SingleResultCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||
applyCustomization();
|
||||
return new SingleResultCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unit);
|
||||
return new SingleResultCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,8 +66,8 @@ public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleRe
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleResultCurrentWeatherRequestCustomizer unit(Unit unit) {
|
||||
this.unit = unit;
|
||||
public SingleResultCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||
this.unitSystem = unitSystem;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -78,8 +78,8 @@ public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleRe
|
||||
if (language != null) {
|
||||
urlBuilder.addRequestParameter("lang", language.getValue());
|
||||
}
|
||||
if (unit != null && unit != Unit.STANDARD_SYSTEM) {
|
||||
urlBuilder.addRequestParameter("units", unit.getValue());
|
||||
if (unitSystem != null && unitSystem != UnitSystem.STANDARD_SYSTEM) {
|
||||
urlBuilder.addRequestParameter("units", unitSystem.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,23 +23,23 @@
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
|
||||
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherRequestTerminator;
|
||||
import com.github.prominence.openweathermap.api.enums.Unit;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
|
||||
public class SingleResultCurrentWeatherRequestTerminatorImpl implements SingleResultCurrentWeatherRequestTerminator {
|
||||
|
||||
private RequestUrlBuilder urlBuilder;
|
||||
private Unit unit;
|
||||
private UnitSystem unitSystem;
|
||||
|
||||
SingleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, Unit unit) {
|
||||
SingleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
this.unit = unit;
|
||||
this.unitSystem = unitSystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Weather asJava() {
|
||||
return new CurrentWeatherResponseMapper(unit).getSingle(asJSON());
|
||||
return new CurrentWeatherResponseMapper(unitSystem).getSingle(asJSON());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -24,27 +24,58 @@ package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The Clouds type represents cloudiness value percentage.
|
||||
* Its value can only be an integer in [0, 100] range.
|
||||
*/
|
||||
public class Clouds {
|
||||
|
||||
private static final String DEFAULT_UNIT = "%";
|
||||
|
||||
private byte value;
|
||||
|
||||
public Clouds() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Clouds.
|
||||
*
|
||||
* @param value the value representing cloudiness percentage.
|
||||
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||
*/
|
||||
public Clouds(byte value) {
|
||||
if (value < 0 || value > 100) {
|
||||
throw new IllegalArgumentException("Cloudiness value must be in [0, 100] range.");
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns cloudiness percentage value.
|
||||
*
|
||||
* @return cloudiness percentage.
|
||||
*/
|
||||
public byte getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets cloudiness percentage value.
|
||||
*
|
||||
* @param value new cloudiness value.
|
||||
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||
*/
|
||||
public void setValue(byte value) {
|
||||
if (value < 0 || value > 100) {
|
||||
throw new IllegalArgumentException("Cloudiness value must be in [0, 100] range.");
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns cloudiness unitSystem. Constantly equals to '%'.
|
||||
*
|
||||
* @return the cloudiness unitSystem.
|
||||
*/
|
||||
public String getUnit() {
|
||||
return "%";
|
||||
return DEFAULT_UNIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -29,6 +29,12 @@ public class Coordinate {
|
||||
private double longitude;
|
||||
|
||||
public Coordinate(double latitude, double longitude) {
|
||||
if (latitude < -90 || latitude > 90) {
|
||||
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
||||
}
|
||||
if (longitude < -180 || longitude > 180) {
|
||||
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
||||
}
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
@ -32,6 +32,12 @@ public class CoordinateRectangle {
|
||||
private double latitudeTop;
|
||||
|
||||
public CoordinateRectangle(double longitudeLeft, double latitudeBottom, double longitudeRight, double latitudeTop) {
|
||||
if (latitudeBottom < -90 || latitudeTop < -90 || latitudeBottom > 90 || latitudeTop > 90) {
|
||||
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
||||
}
|
||||
if (longitudeLeft < -180 || longitudeRight < -180 || longitudeLeft > 180 || longitudeRight > 180) {
|
||||
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
||||
}
|
||||
this.longitudeLeft = longitudeLeft;
|
||||
this.latitudeBottom = latitudeBottom;
|
||||
this.longitudeRight = longitudeRight;
|
||||
@ -54,7 +60,7 @@ public class CoordinateRectangle {
|
||||
return latitudeTop;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
public String getFormattedString() {
|
||||
return longitudeLeft + "," + latitudeBottom + "," + longitudeRight + "," + latitudeTop;
|
||||
}
|
||||
|
||||
@ -76,6 +82,6 @@ public class CoordinateRectangle {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Rectangle: " + getValue();
|
||||
return "Rectangle: " + getFormattedString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,27 +24,58 @@ package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The Humidity type represents humidity value percentage.
|
||||
* Its value can only be an integer in [0, 100] range.
|
||||
*/
|
||||
public class Humidity {
|
||||
|
||||
private static final String DEFAULT_UNIT = "%";
|
||||
|
||||
private int value;
|
||||
|
||||
public Humidity() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Humidity.
|
||||
*
|
||||
* @param value the value representing humidity percentage.
|
||||
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||
*/
|
||||
public Humidity(byte value) {
|
||||
if (value < 0 || value > 100) {
|
||||
throw new IllegalArgumentException("Humidity value must be in [0, 100] range.");
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns humidity percentage value.
|
||||
*
|
||||
* @return humidity percentage.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets humidity percentage value.
|
||||
*
|
||||
* @param value new humidity value.
|
||||
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||
*/
|
||||
public void setValue(int value) {
|
||||
if (value < 0 || value > 100) {
|
||||
throw new IllegalArgumentException("Humidity value must be in [0, 100] range.");
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns humidity unitSystem. Constantly equals to '%'.
|
||||
*
|
||||
* @return the humidity unitSystem.
|
||||
*/
|
||||
public String getUnit() {
|
||||
return "%";
|
||||
return DEFAULT_UNIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -28,9 +28,9 @@ import java.util.Objects;
|
||||
|
||||
public class Location {
|
||||
|
||||
private String countryCode;
|
||||
private int id;
|
||||
private String name;
|
||||
private Integer id;
|
||||
private String countryCode;
|
||||
|
||||
private LocalDateTime sunrise;
|
||||
private LocalDateTime sunset;
|
||||
@ -38,12 +38,20 @@ public class Location {
|
||||
|
||||
private Coordinate coordinate;
|
||||
|
||||
public String getCountryCode() {
|
||||
return countryCode;
|
||||
public Location(int id, String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Name must be set.");
|
||||
}
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setCountryCode(String countryCode) {
|
||||
this.countryCode = countryCode;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -54,12 +62,12 @@ public class Location {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
public String getCountryCode() {
|
||||
return countryCode;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
public void setCountryCode(String countryCode) {
|
||||
this.countryCode = countryCode;
|
||||
}
|
||||
|
||||
public LocalDateTime getSunrise() {
|
||||
@ -99,9 +107,9 @@ public class Location {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Location)) return false;
|
||||
Location location = (Location) o;
|
||||
return Objects.equals(countryCode, location.countryCode) &&
|
||||
return id == location.id &&
|
||||
Objects.equals(name, location.name) &&
|
||||
Objects.equals(id, location.id) &&
|
||||
Objects.equals(countryCode, location.countryCode) &&
|
||||
Objects.equals(sunrise, location.sunrise) &&
|
||||
Objects.equals(sunset, location.sunset) &&
|
||||
Objects.equals(zoneOffset, location.zoneOffset) &&
|
||||
@ -110,15 +118,25 @@ public class Location {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(countryCode, name, id, sunrise, sunset, zoneOffset, coordinate);
|
||||
return Objects.hash(id, name, countryCode, sunrise, sunset, zoneOffset, coordinate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String result = coordinate != null ? (coordinate.toString() + ", ") : "";
|
||||
return result +
|
||||
"Country code: '" + countryCode + '\'' +
|
||||
", Name: '" + name + '\'' +
|
||||
", ID: " + id;
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
if (coordinate != null) {
|
||||
stringBuilder.append(coordinate.toString());
|
||||
stringBuilder.append(". ");
|
||||
}
|
||||
stringBuilder.append("ID: ");
|
||||
stringBuilder.append(id);
|
||||
stringBuilder.append(", Name: ");
|
||||
stringBuilder.append(name);
|
||||
if (countryCode != null) {
|
||||
stringBuilder.append('(');
|
||||
stringBuilder.append(countryCode);
|
||||
stringBuilder.append(')');
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,46 +24,105 @@ package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The Pressure type represents pressure value percentage.
|
||||
* Its value can only be a double in [0, +∞) range.
|
||||
*/
|
||||
public class Pressure {
|
||||
|
||||
private static final String DEFAULT_UNIT = "hPa";
|
||||
|
||||
private double value;
|
||||
|
||||
private double seaLevelValue;
|
||||
private double groundLevelValue;
|
||||
|
||||
public Pressure() {
|
||||
}
|
||||
private Double seaLevelValue;
|
||||
private Double groundLevelValue;
|
||||
|
||||
/**
|
||||
* Instantiates a new Pressure.
|
||||
*
|
||||
* @param value the value representing pressure value.
|
||||
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||
*/
|
||||
public Pressure(double value) {
|
||||
if (value < 0) {
|
||||
throw new IllegalArgumentException("Pressure value must be in [0, +∞) range.");
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pressure value.
|
||||
*
|
||||
* @return pressure value.
|
||||
*/
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets pressure value.
|
||||
*
|
||||
* @param value new pressure value.
|
||||
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||
*/
|
||||
public void setValue(double value) {
|
||||
if (value < 0) {
|
||||
throw new IllegalArgumentException("Pressure value must be in [0, +∞) range.");
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public double getSeaLevelValue() {
|
||||
/**
|
||||
* Gets sea level value.
|
||||
*
|
||||
* @return the sea level value.
|
||||
*/
|
||||
public Double getSeaLevelValue() {
|
||||
return seaLevelValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets sea level value.
|
||||
*
|
||||
* @param seaLevelValue the sea level value.
|
||||
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||
*/
|
||||
public void setSeaLevelValue(double seaLevelValue) {
|
||||
if (seaLevelValue < 0) {
|
||||
throw new IllegalArgumentException("Pressure value must be in [0, +∞) range.");
|
||||
}
|
||||
this.seaLevelValue = seaLevelValue;
|
||||
}
|
||||
|
||||
public double getGroundLevelValue() {
|
||||
/**
|
||||
* Gets ground level value.
|
||||
*
|
||||
* @return the ground level value.
|
||||
*/
|
||||
public Double getGroundLevelValue() {
|
||||
return groundLevelValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ground level value.
|
||||
*
|
||||
* @param groundLevelValue the ground level value.
|
||||
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||
*/
|
||||
public void setGroundLevelValue(double groundLevelValue) {
|
||||
if (groundLevelValue < 0) {
|
||||
throw new IllegalArgumentException("Pressure value must be in [0, +∞) range.");
|
||||
}
|
||||
this.groundLevelValue = groundLevelValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pressure unitSystem. Constantly equals to 'hPa'.
|
||||
*
|
||||
* @return the pressure unitSystem.
|
||||
*/
|
||||
public String getUnit() {
|
||||
return "hPa";
|
||||
return DEFAULT_UNIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,8 +131,8 @@ public class Pressure {
|
||||
if (!(o instanceof Pressure)) return false;
|
||||
Pressure pressure = (Pressure) o;
|
||||
return Double.compare(pressure.value, value) == 0 &&
|
||||
Double.compare(pressure.seaLevelValue, seaLevelValue) == 0 &&
|
||||
Double.compare(pressure.groundLevelValue, groundLevelValue) == 0;
|
||||
Objects.equals(seaLevelValue, pressure.seaLevelValue) &&
|
||||
Objects.equals(groundLevelValue, pressure.groundLevelValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -26,35 +26,37 @@ import java.util.Objects;
|
||||
|
||||
public class Rain {
|
||||
|
||||
private double oneHourRainLevel;
|
||||
private double threeHourRainLevel;
|
||||
private static final String DEFAULT_UNIT = "mm";
|
||||
|
||||
private Double oneHourRainLevel;
|
||||
private Double threeHourRainLevel;
|
||||
|
||||
public Rain() {
|
||||
}
|
||||
|
||||
public Rain(double oneHourRainLevel, double threeHourRainLevel) {
|
||||
public Rain(Double oneHourRainLevel, Double threeHourRainLevel) {
|
||||
this.oneHourRainLevel = oneHourRainLevel;
|
||||
this.threeHourRainLevel = threeHourRainLevel;
|
||||
}
|
||||
|
||||
public double getOneHourRainLevel() {
|
||||
public Double getOneHourRainLevel() {
|
||||
return oneHourRainLevel;
|
||||
}
|
||||
|
||||
public void setOneHourRainLevel(double oneHourRainLevel) {
|
||||
public void setOneHourRainLevel(Double oneHourRainLevel) {
|
||||
this.oneHourRainLevel = oneHourRainLevel;
|
||||
}
|
||||
|
||||
public double getThreeHourRainLevel() {
|
||||
public Double getThreeHourRainLevel() {
|
||||
return threeHourRainLevel;
|
||||
}
|
||||
|
||||
public void setThreeHourRainLevel(double threeHourRainLevel) {
|
||||
public void setThreeHourRainLevel(Double threeHourRainLevel) {
|
||||
this.threeHourRainLevel = threeHourRainLevel;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return "mm";
|
||||
return DEFAULT_UNIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,8 +64,8 @@ public class Rain {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Rain)) return false;
|
||||
Rain rain = (Rain) o;
|
||||
return Double.compare(rain.oneHourRainLevel, oneHourRainLevel) == 0 &&
|
||||
Double.compare(rain.threeHourRainLevel, threeHourRainLevel) == 0;
|
||||
return Objects.equals(oneHourRainLevel, rain.oneHourRainLevel) &&
|
||||
Objects.equals(threeHourRainLevel, rain.threeHourRainLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,7 +75,24 @@ public class Rain {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "1 last hour rain level: " + oneHourRainLevel + + ' ' + getUnit() +
|
||||
", 3 last hours rain level: " + threeHourRainLevel + ' ' + getUnit();
|
||||
StringBuilder snowString = new StringBuilder();
|
||||
if (oneHourRainLevel == null && threeHourRainLevel == null) {
|
||||
snowString.append("unknown");
|
||||
} else {
|
||||
if (oneHourRainLevel != null) {
|
||||
snowString.append("1 last hour rain level: ");
|
||||
snowString.append(oneHourRainLevel);
|
||||
snowString.append(getUnit());
|
||||
}
|
||||
if (threeHourRainLevel != null) {
|
||||
if (oneHourRainLevel != null) {
|
||||
snowString.append(", ");
|
||||
}
|
||||
snowString.append("3 last hours rain level: ");
|
||||
snowString.append(threeHourRainLevel);
|
||||
snowString.append(getUnit());
|
||||
}
|
||||
}
|
||||
return snowString.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,45 +26,46 @@ import java.util.Objects;
|
||||
|
||||
public class Snow {
|
||||
|
||||
private double oneHourSnowLevel;
|
||||
private double threeHourSnowLevel;
|
||||
private static final String DEFAULT_UNIT = "mm";
|
||||
|
||||
private Double oneHourSnowLevel;
|
||||
private Double threeHourSnowLevel;
|
||||
|
||||
public Snow() {
|
||||
}
|
||||
|
||||
public Snow(double oneHourSnowLevel, double threeHourSnowLevel) {
|
||||
public Snow(Double oneHourSnowLevel, Double threeHourSnowLevel) {
|
||||
this.oneHourSnowLevel = oneHourSnowLevel;
|
||||
this.threeHourSnowLevel = threeHourSnowLevel;
|
||||
}
|
||||
|
||||
public double getOneHourSnowLevel() {
|
||||
public Double getOneHourSnowLevel() {
|
||||
return oneHourSnowLevel;
|
||||
}
|
||||
|
||||
public void setOneHourSnowLevel(double oneHourSnowLevel) {
|
||||
public void setOneHourSnowLevel(Double oneHourSnowLevel) {
|
||||
this.oneHourSnowLevel = oneHourSnowLevel;
|
||||
}
|
||||
|
||||
public double getThreeHourSnowLevel() {
|
||||
public Double getThreeHourSnowLevel() {
|
||||
return threeHourSnowLevel;
|
||||
}
|
||||
|
||||
public void setThreeHourSnowLevel(double threeHourSnowLevel) {
|
||||
public void setThreeHourSnowLevel(Double threeHourSnowLevel) {
|
||||
this.threeHourSnowLevel = threeHourSnowLevel;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return "mm";
|
||||
return DEFAULT_UNIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Snow)) return false;
|
||||
Snow snow = (Snow) o;
|
||||
return Double.compare(snow.oneHourSnowLevel, oneHourSnowLevel) == 0 &&
|
||||
Double.compare(snow.threeHourSnowLevel, threeHourSnowLevel) == 0;
|
||||
return Objects.equals(oneHourSnowLevel, snow.oneHourSnowLevel) &&
|
||||
Objects.equals(threeHourSnowLevel, snow.threeHourSnowLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,7 +75,24 @@ public class Snow {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "1 last hour snow level: " + oneHourSnowLevel + ' ' + getUnit() +
|
||||
", 3 last hours snow level: " + threeHourSnowLevel + ' ' + getUnit();
|
||||
StringBuilder snowString = new StringBuilder();
|
||||
if (oneHourSnowLevel == null && threeHourSnowLevel == null) {
|
||||
snowString.append("unknown");
|
||||
} else {
|
||||
if (oneHourSnowLevel != null) {
|
||||
snowString.append("1 last hour snow level: ");
|
||||
snowString.append(oneHourSnowLevel);
|
||||
snowString.append(getUnit());
|
||||
}
|
||||
if (threeHourSnowLevel != null) {
|
||||
if (oneHourSnowLevel != null) {
|
||||
snowString.append(", ");
|
||||
}
|
||||
snowString.append("3 last hours snow level: ");
|
||||
snowString.append(threeHourSnowLevel);
|
||||
snowString.append(getUnit());
|
||||
}
|
||||
}
|
||||
return snowString.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,10 +27,18 @@ import java.util.Objects;
|
||||
public class Temperature {
|
||||
|
||||
private double value;
|
||||
private double maxTemperature;
|
||||
private double minTemperature;
|
||||
private Double maxTemperature;
|
||||
private Double minTemperature;
|
||||
private String unit;
|
||||
|
||||
public Temperature(double value, String unit) {
|
||||
if (unit == null) {
|
||||
throw new IllegalArgumentException("Unit must be set.");
|
||||
}
|
||||
this.value = value;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
@ -39,19 +47,19 @@ public class Temperature {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public double getMaxTemperature() {
|
||||
public Double getMaxTemperature() {
|
||||
return maxTemperature;
|
||||
}
|
||||
|
||||
public void setMaxTemperature(double maxTemperature) {
|
||||
public void setMaxTemperature(Double maxTemperature) {
|
||||
this.maxTemperature = maxTemperature;
|
||||
}
|
||||
|
||||
public double getMinTemperature() {
|
||||
public Double getMinTemperature() {
|
||||
return minTemperature;
|
||||
}
|
||||
|
||||
public void setMinTemperature(double minTemperature) {
|
||||
public void setMinTemperature(Double minTemperature) {
|
||||
this.minTemperature = minTemperature;
|
||||
}
|
||||
|
||||
@ -60,6 +68,9 @@ public class Temperature {
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
if (unit == null) {
|
||||
throw new IllegalArgumentException("Unit must be set.");
|
||||
}
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@ -69,8 +80,8 @@ public class Temperature {
|
||||
if (!(o instanceof Temperature)) return false;
|
||||
Temperature that = (Temperature) o;
|
||||
return Double.compare(that.value, value) == 0 &&
|
||||
Double.compare(that.maxTemperature, maxTemperature) == 0 &&
|
||||
Double.compare(that.minTemperature, minTemperature) == 0 &&
|
||||
Objects.equals(maxTemperature, that.maxTemperature) &&
|
||||
Objects.equals(minTemperature, that.minTemperature) &&
|
||||
Objects.equals(unit, that.unit);
|
||||
}
|
||||
|
||||
@ -81,8 +92,24 @@ public class Temperature {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Temperature: " + value + ' ' + unit +
|
||||
", Maximum value: " + maxTemperature + ' ' + unit +
|
||||
", Minimum value: " + minTemperature + ' ' + unit;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("Temperature: ");
|
||||
stringBuilder.append(value);
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(unit);
|
||||
if (maxTemperature != null) {
|
||||
stringBuilder.append(", Maximum value: ");
|
||||
stringBuilder.append(maxTemperature);
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(unit);
|
||||
}
|
||||
if (minTemperature != null) {
|
||||
stringBuilder.append(", Minimum value: ");
|
||||
stringBuilder.append(minTemperature);
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(unit);
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,8 +27,8 @@ import java.util.Objects;
|
||||
|
||||
public class Weather {
|
||||
|
||||
private String weatherState;
|
||||
private String weatherDescription;
|
||||
private String state;
|
||||
private String description;
|
||||
private String weatherIconUrl;
|
||||
private LocalDateTime requestedOn;
|
||||
|
||||
@ -42,20 +42,37 @@ public class Weather {
|
||||
|
||||
private Location location;
|
||||
|
||||
public String getWeatherState() {
|
||||
return weatherState;
|
||||
public Weather(String state, String description) {
|
||||
if (state == null) {
|
||||
throw new IllegalArgumentException("State must be set.");
|
||||
}
|
||||
if (description == null) {
|
||||
throw new IllegalArgumentException("Description must be set.");
|
||||
}
|
||||
this.state = state;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void setWeatherState(String weatherState) {
|
||||
this.weatherState = weatherState;
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public String getWeatherDescription() {
|
||||
return weatherDescription;
|
||||
public void setState(String state) {
|
||||
if (state == null) {
|
||||
throw new IllegalArgumentException("State must be set.");
|
||||
}
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public void setWeatherDescription(String weatherDescription) {
|
||||
this.weatherDescription = weatherDescription;
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
if (description == null) {
|
||||
throw new IllegalArgumentException("Description must be set.");
|
||||
}
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getWeatherIconUrl() {
|
||||
@ -143,8 +160,8 @@ public class Weather {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Weather)) return false;
|
||||
Weather weather = (Weather) o;
|
||||
return Objects.equals(weatherState, weather.weatherState) &&
|
||||
Objects.equals(weatherDescription, weather.weatherDescription) &&
|
||||
return Objects.equals(state, weather.state) &&
|
||||
Objects.equals(description, weather.description) &&
|
||||
Objects.equals(weatherIconUrl, weather.weatherIconUrl) &&
|
||||
Objects.equals(requestedOn, weather.requestedOn) &&
|
||||
Objects.equals(temperature, weather.temperature) &&
|
||||
@ -159,25 +176,54 @@ public class Weather {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(weatherState, weatherDescription, weatherIconUrl, requestedOn, temperature, pressure, humidity, wind, rain, snow, clouds, location);
|
||||
return Objects.hash(state, description, weatherIconUrl, requestedOn, temperature, pressure, humidity, wind, rain, snow, clouds, location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final String countryCode = location.getCountryCode();
|
||||
String resultString = "Location: " +
|
||||
location.getName() + (countryCode != null ? ('(' + countryCode + ")") : "") +
|
||||
", Weather: " + weatherDescription +
|
||||
", " + temperature.getValue() + ' ' + temperature.getUnit() +
|
||||
", " + pressure.getValue() + ' ' + pressure.getUnit() +
|
||||
", " + clouds.toString();
|
||||
if (rain != null) {
|
||||
resultString += (", Rain: " + rain.getOneHourRainLevel() + ' ' + rain.getUnit());
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
if (location != null) {
|
||||
stringBuilder.append("Location: ");
|
||||
stringBuilder.append(location.getName());
|
||||
|
||||
final String countryCode = location.getCountryCode();
|
||||
if (countryCode != null) {
|
||||
stringBuilder.append('(');
|
||||
stringBuilder.append(countryCode);
|
||||
stringBuilder.append(')');
|
||||
}
|
||||
}
|
||||
if (snow != null) {
|
||||
resultString += (", Snow: " + snow.getOneHourSnowLevel() + ' ' + snow.getUnit());
|
||||
stringBuilder.append(", Weather: ");
|
||||
stringBuilder.append(description);
|
||||
if (temperature != null) {
|
||||
stringBuilder.append(", ");
|
||||
stringBuilder.append(temperature.getValue());
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(temperature.getUnit());
|
||||
}
|
||||
return resultString;
|
||||
if (pressure != null) {
|
||||
stringBuilder.append(", ");
|
||||
stringBuilder.append(pressure.getValue());
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(pressure.getUnit());
|
||||
}
|
||||
if (clouds != null) {
|
||||
stringBuilder.append(", ");
|
||||
stringBuilder.append(clouds.toString());
|
||||
}
|
||||
if (rain != null && rain.getOneHourRainLevel() != null) {
|
||||
stringBuilder.append(", Rain: ");
|
||||
stringBuilder.append(rain.getOneHourRainLevel());
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(rain.getUnit());
|
||||
}
|
||||
if (snow != null && snow.getOneHourSnowLevel() != null) {
|
||||
stringBuilder.append(", Snow: ");
|
||||
stringBuilder.append(snow.getOneHourSnowLevel());
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(snow.getUnit());
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,33 +24,92 @@ package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The type Wind.
|
||||
*/
|
||||
public class Wind {
|
||||
|
||||
private double speed;
|
||||
private double degrees;
|
||||
private Double degrees;
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
* Instantiates a new Wind.
|
||||
*
|
||||
* @param speed the speed
|
||||
* @param unit the unitSystem
|
||||
*/
|
||||
public Wind(double speed, String unit) {
|
||||
if (speed < 0) {
|
||||
throw new IllegalArgumentException("Wind speed value must be in positive or zero.");
|
||||
}
|
||||
if (unit == null) {
|
||||
throw new IllegalArgumentException("Unit must be set.");
|
||||
}
|
||||
this.speed = speed;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets speed.
|
||||
*
|
||||
* @return the speed
|
||||
*/
|
||||
public double getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets speed.
|
||||
*
|
||||
* @param speed the speed
|
||||
*/
|
||||
public void setSpeed(double speed) {
|
||||
if (speed < 0) {
|
||||
throw new IllegalArgumentException("Wind speed value must be in positive or zero.");
|
||||
}
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public double getDegrees() {
|
||||
/**
|
||||
* Gets degrees.
|
||||
*
|
||||
* @return the degrees
|
||||
*/
|
||||
public Double getDegrees() {
|
||||
return degrees;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets degrees.
|
||||
*
|
||||
* @param degrees the degrees
|
||||
*/
|
||||
public void setDegrees(double degrees) {
|
||||
if (degrees < 0 || degrees > 360) {
|
||||
throw new IllegalArgumentException("Wind direction value must be in [0, 360] range.");
|
||||
}
|
||||
this.degrees = degrees;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets unitSystem.
|
||||
*
|
||||
* @return the unitSystem
|
||||
*/
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets unitSystem.
|
||||
*
|
||||
* @param unit the unitSystem
|
||||
*/
|
||||
public void setUnit(String unit) {
|
||||
if (unit == null) {
|
||||
throw new IllegalArgumentException("Unit must be set.");
|
||||
}
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@ -60,7 +119,7 @@ public class Wind {
|
||||
if (!(o instanceof Wind)) return false;
|
||||
Wind wind = (Wind) o;
|
||||
return Double.compare(wind.speed, speed) == 0 &&
|
||||
Double.compare(wind.degrees, degrees) == 0 &&
|
||||
Objects.equals(degrees, wind.degrees) &&
|
||||
Objects.equals(unit, wind.unit);
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.test;
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.github.prominence.openweathermap.api.impl.OpenWeatherMapClient;
|
||||
import org.junit.BeforeClass;
|
||||
@ -20,11 +20,14 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.test;
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
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.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||
import com.github.prominence.openweathermap.api.impl.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;
|
||||
@ -43,8 +46,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byCoordinate(new Coordinate(5, 5))
|
||||
.accuracy(Accuracy.ACCURATE)
|
||||
.language(Language.ROMANIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@ -59,7 +61,6 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byCityId(350001514)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@ -74,7 +75,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byCityName("Minsk")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@ -89,7 +90,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byCityName("Moscow", "ru")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@ -104,7 +105,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@ -119,7 +120,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
@ -134,7 +135,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
@ -149,7 +150,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asHTML();
|
||||
|
||||
@ -164,7 +165,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
|
||||
@ -179,7 +180,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
@ -194,7 +195,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
@ -209,7 +210,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asHTML();
|
||||
|
||||
@ -225,7 +226,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.byRectangle(new CoordinateRectangle(12, 32, 15, 37), 10)
|
||||
.accuracy(Accuracy.ACCURATE)
|
||||
.language(Language.ROMANIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@ -242,7 +243,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.byRectangle(new CoordinateRectangle(12, 32, 15, 37), 10, true)
|
||||
.accuracy(Accuracy.ACCURATE)
|
||||
.language(Language.ROMANIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@ -258,7 +259,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@ -274,7 +275,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@ -290,7 +291,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
@ -305,7 +306,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
@ -320,7 +321,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asHTML();
|
||||
|
||||
@ -335,7 +336,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
@ -352,7 +353,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
|
||||
@ -367,7 +368,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
@ -382,11 +383,32 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.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 = DataNotFoundException.class)
|
||||
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
|
||||
getClient()
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCityName("InvalidCity")
|
||||
.retrieve()
|
||||
.asJava();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CloudsUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateCloudsWithValidArgs_thenValueIsSet() {
|
||||
Clouds clouds = new Clouds((byte) 100);
|
||||
assert clouds.getValue() == 100;
|
||||
|
||||
assert new Clouds((byte) 0).getValue() == 0;
|
||||
assert new Clouds((byte) 100).getValue() == 100;
|
||||
assert new Clouds((byte) 55).getValue() == 55;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCloudsByConstructorWithInvalidDataAboveHundred_thenThrowAnException() {
|
||||
new Clouds((byte) 110);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCloudsByConstructorWithInvalidDataNegative_thenThrowAnException() {
|
||||
new Clouds((byte) -33);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValidValues_thenAllIsFine() {
|
||||
Clouds clouds = new Clouds((byte) 14);
|
||||
clouds.setValue((byte) 0);
|
||||
clouds.setValue((byte) 15);
|
||||
clouds.setValue((byte) 100);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCloudsAndSetInvalidDataAboveHundred_thenThrowAnException() {
|
||||
Clouds clouds = new Clouds((byte) 12);
|
||||
clouds.setValue((byte) 112);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCloudsAndSetInvalidDataNegative_thenThrowAnException() {
|
||||
Clouds clouds = new Clouds((byte) 88);
|
||||
clouds.setValue((byte) -89);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
|
||||
Clouds one = new Clouds((byte) 22);
|
||||
Clouds two = new Clouds((byte) 22);
|
||||
|
||||
assert one.equals(two);
|
||||
assert one.equals(one);
|
||||
assert one.hashCode() == two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
|
||||
Clouds one = new Clouds((byte) 5);
|
||||
Clouds two = new Clouds((byte) 88);
|
||||
|
||||
assert !one.equals(two);
|
||||
assert !two.equals(one);
|
||||
assert !one.equals(new Object());
|
||||
assert one.hashCode() != two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final String cloudsString = new Clouds((byte) 44).toString();
|
||||
assert cloudsString != null;
|
||||
assert !"".equals(cloudsString);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,107 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CoordinateRectangleUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||
new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLatitudeBottomBelowMinus90_thenThrowAnException() {
|
||||
new CoordinateRectangle(44.5, -91.2, 54.4, 22.2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLatitudeBottomAbove90_thenThrowAnException() {
|
||||
new CoordinateRectangle(44.5, 91.2, 54.4, 22.2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLatitudeTopBelowMinus90_thenThrowAnException() {
|
||||
new CoordinateRectangle(44.5, 22.4, 54.4, -92.3);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLatitudeTopAbove90_thenThrowAnException() {
|
||||
new CoordinateRectangle(44.5, 22.5, 54.4, 94.887);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLongitudeLeftBelowMinus180_thenThrowAnException() {
|
||||
new CoordinateRectangle(-944.5, 22.4, 54.4, 22.2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLongitudeLeftAbove180_thenThrowAnException() {
|
||||
new CoordinateRectangle(544.5, 22.4, 54.4, 22.2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLongitudeRightBelowMinus180_thenThrowAnException() {
|
||||
new CoordinateRectangle(44.5, 22.4, -254.4, 22.2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLongitudeRightAbove180_thenThrowAnException() {
|
||||
new CoordinateRectangle(44.5, 22.4, 354.4, 22.2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetAllParameters_thenAllIsFine() {
|
||||
final CoordinateRectangle rectangle = new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
assert rectangle.getLongitudeLeft() == 44.5;
|
||||
assert rectangle.getLatitudeBottom() == 22.4;
|
||||
assert rectangle.getLongitudeRight() == 54.4;
|
||||
assert rectangle.getLatitudeTop() == 22.2;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final CoordinateRectangle rectangle = new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
|
||||
assert rectangle.toString() != null;
|
||||
assert !"".equals(rectangle.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallHashCode_thenAllIsFine() {
|
||||
final CoordinateRectangle first = new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
final CoordinateRectangle second = new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
final CoordinateRectangle third = new CoordinateRectangle(44.5, 22.4, 54.4, 23.566);
|
||||
|
||||
assert first.hashCode() != third.hashCode();
|
||||
assert second.hashCode() != third.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
CoordinateRectangle first = new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
CoordinateRectangle second = new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
|
||||
assert first.equals(second);
|
||||
assert first.equals(first);
|
||||
assert !first.equals(new Object());
|
||||
|
||||
first = new CoordinateRectangle(49.5, 22.4, 54.4, 22.2);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first = new CoordinateRectangle(44.5, 29.4, 54.4, 22.2);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first = new CoordinateRectangle(44.5, 22.4, 24.4, 22.2);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first = new CoordinateRectangle(44.5, 22.4, 54.4, -2.2);
|
||||
|
||||
assert !first.equals(second);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,141 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CoordinateUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateCoordinateWithValidValues_thenObjectCreated() {
|
||||
new Coordinate(44, 53);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCoordinateWithInvalidLatitudeBelowMinus90_thenThrowAnException() {
|
||||
new Coordinate(-333, 44);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCoordinateWithInvalidLatitudeAbove90_thenThrowAnException() {
|
||||
new Coordinate(223, 44);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCoordinateWithInvalidLongitudeBelowMinus180_thenThrowAnException() {
|
||||
new Coordinate(33, -999);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCoordinateWithInvalidLongitudeAbove180_thenThrowAnException() {
|
||||
new Coordinate(33, 999);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValidCoordinates_thenAllIsFine() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
|
||||
coordinate.setLatitude(-90);
|
||||
coordinate.setLatitude(90);
|
||||
coordinate.setLatitude(44);
|
||||
|
||||
coordinate.setLongitude(-180);
|
||||
coordinate.setLongitude(180);
|
||||
coordinate.setLongitude(130);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidLatitudeBelowMinus90_thenThrowAnException() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
coordinate.setLatitude(-91);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidLatitudeAbove90_thenThrowAnException() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
coordinate.setLatitude(92);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidLongitudeBelowMinus180_thenThrowAnException() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
coordinate.setLongitude(-194);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidLongitudeAbove180_thenThrowAnException() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
coordinate.setLongitude(444);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetLatitude_thenAllIsFine() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
assert coordinate.getLatitude() == 0;
|
||||
|
||||
coordinate.setLatitude(45);
|
||||
|
||||
assert coordinate.getLatitude() == 45;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetLongitude_thenAllIsFine() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
assert coordinate.getLongitude() == 0;
|
||||
|
||||
coordinate.setLongitude(33);
|
||||
|
||||
assert coordinate.getLongitude() == 33;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
assert coordinate.toString() != null;
|
||||
assert !"".equals(coordinate.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void RainwhenCallHashCode_thenAllIsFine() {
|
||||
final Coordinate first = new Coordinate(22, 66);
|
||||
final Coordinate second = new Coordinate(22, 44);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
second.setLongitude(66);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
second.setLatitude(89);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
first.setLatitude(89);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Coordinate first = new Coordinate(11, 99);
|
||||
final Coordinate second = new Coordinate(11, 99);
|
||||
|
||||
assert first.equals(second);
|
||||
assert first.equals(first);
|
||||
assert !first.equals(new Object());
|
||||
|
||||
first.setLatitude(34);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
second.setLatitude(34);
|
||||
|
||||
assert first.equals(second);
|
||||
|
||||
second.setLongitude(74);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first.setLongitude(74);
|
||||
|
||||
assert first.equals(second);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class HumidityUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateHumidityWithArgs_thenValueIsSet() {
|
||||
Humidity humidity = new Humidity((byte) 100);
|
||||
assert humidity.getValue() == 100;
|
||||
|
||||
assert new Humidity((byte) 0).getValue() == 0;
|
||||
assert new Humidity((byte) 100).getValue() == 100;
|
||||
assert new Humidity((byte) 55).getValue() == 55;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateHumidityByConstructorWithInvalidDataAboveHundred_thenThrowAnException() {
|
||||
new Humidity((byte) 112);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateHumidityByConstructorWithInvalidDataNegative_thenThrowAnException() {
|
||||
new Humidity((byte) -33);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValidValues_thenAllIsFine() {
|
||||
Humidity humidity = new Humidity((byte) 14);
|
||||
humidity.setValue((byte) 0);
|
||||
humidity.setValue((byte) 15);
|
||||
humidity.setValue((byte) 100);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateHumidityAndSetInvalidDataAboveHundred_thenThrowAnException() {
|
||||
Humidity humidity = new Humidity((byte) 12);
|
||||
humidity.setValue((byte) 112);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateHumidityAndSetInvalidDataNegative_thenThrowAnException() {
|
||||
Humidity humidity = new Humidity((byte) 88);
|
||||
humidity.setValue((byte) -89);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
|
||||
Humidity one = new Humidity((byte) 22);
|
||||
Humidity two = new Humidity((byte) 22);
|
||||
|
||||
assert one.equals(two);
|
||||
assert one.equals(one);
|
||||
assert one.hashCode() == two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
|
||||
Humidity one = new Humidity((byte) 5);
|
||||
Humidity two = new Humidity((byte) 88);
|
||||
|
||||
assert !one.equals(two);
|
||||
assert !two.equals(one);
|
||||
assert !one.equals(new Object());
|
||||
assert one.hashCode() != two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final String humidityString = new Humidity((byte) 44).toString();
|
||||
assert humidityString != null;
|
||||
assert !"".equals(humidityString);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,177 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
public class LocationUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||
new Location(33, "test");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithoutName_thenThrowAnException() {
|
||||
new Location(33, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetId_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
location.setId(55);
|
||||
|
||||
assert location.getId() == 55;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetName_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
location.setName("city");
|
||||
|
||||
assert "city".equals(location.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetCountryCode_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
location.setCountryCode("by");
|
||||
|
||||
assert "by".equals(location.getCountryCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetSunrise_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
location.setSunrise(now);
|
||||
|
||||
assert now.equals(location.getSunrise());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetSunset_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
location.setSunset(now);
|
||||
|
||||
assert now.equals(location.getSunset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetZoneOffset_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
final ZoneOffset offset = ZoneOffset.UTC;
|
||||
location.setZoneOffset(offset);
|
||||
|
||||
assert offset.equals(location.getZoneOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetCoordinate_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
final Coordinate coordinate = new Coordinate(33.2, 64.2);
|
||||
location.setCoordinate(coordinate);
|
||||
|
||||
assert coordinate.equals(location.getCoordinate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Location location = new Location(44, "test");
|
||||
|
||||
assert !"".equals(location.toString());
|
||||
|
||||
location.setCoordinate(new Coordinate(33.2, 56.3));
|
||||
|
||||
assert !"".equals(location.toString());
|
||||
|
||||
location.setCountryCode("TN");
|
||||
|
||||
assert !"".equals(location.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallHashCode_thenAllIsFine() {
|
||||
final Location one = new Location(44, "test");
|
||||
final Location two = new Location(44, "test");
|
||||
|
||||
assert one.hashCode() == two.hashCode();
|
||||
|
||||
two.setName("112");
|
||||
|
||||
assert one.hashCode() != two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Location one = new Location(44, "test");
|
||||
final Location two = new Location(44, "test");
|
||||
|
||||
assert one.equals(one);
|
||||
assert !one.equals(new Object());
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
two.setId(23);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
one.setId(23);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setName("23");
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setName("23");
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setCountryCode("11");
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setCountryCode("11");
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
one.setSunrise(now);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setSunrise(now);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setSunset(now);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setSunset(now);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setZoneOffset(ZoneOffset.UTC);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setZoneOffset(ZoneOffset.UTC);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Coordinate coordinate = new Coordinate(33.5, -22.4);
|
||||
|
||||
one.setCoordinate(coordinate);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setCoordinate(coordinate);
|
||||
|
||||
assert one.equals(two);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class PressureUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreatePressureWithArgs_thenValueIsSet() {
|
||||
Pressure pressure = new Pressure(100);
|
||||
assert pressure.getValue() == 100;
|
||||
|
||||
assert new Pressure(0).getValue() == 0;
|
||||
assert new Pressure(100).getValue() == 100;
|
||||
assert new Pressure(55).getValue() == 55;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
|
||||
Pressure one = new Pressure(22);
|
||||
Pressure two = new Pressure(22);
|
||||
|
||||
assert one.equals(two);
|
||||
assert one.equals(one);
|
||||
assert one.hashCode() == two.hashCode();
|
||||
|
||||
one.setSeaLevelValue(333);
|
||||
one.setGroundLevelValue(555);
|
||||
|
||||
two.setSeaLevelValue(333);
|
||||
two.setGroundLevelValue(555);
|
||||
|
||||
assert one.equals(two);
|
||||
assert two.equals(one);
|
||||
assert one.hashCode() == two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
|
||||
Pressure one = new Pressure(5);
|
||||
Pressure two = new Pressure(88);
|
||||
|
||||
assert !one.equals(two);
|
||||
assert !two.equals(one);
|
||||
assert !one.equals(new Object());
|
||||
assert one.hashCode() != two.hashCode();
|
||||
|
||||
one = new Pressure(44);
|
||||
one.setSeaLevelValue(44);
|
||||
two = new Pressure(44);
|
||||
two.setGroundLevelValue(22);
|
||||
|
||||
assert !one.equals(two);
|
||||
assert !two.equals(one);
|
||||
|
||||
two.setSeaLevelValue(44);
|
||||
|
||||
assert !one.equals(two);
|
||||
assert !two.equals(one);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValidValues_thenAllIsFine() {
|
||||
Pressure pressure = new Pressure(14);
|
||||
pressure.setValue(0);
|
||||
pressure.setValue(15);
|
||||
pressure.setValue(100);
|
||||
|
||||
pressure.setGroundLevelValue(222);
|
||||
assert pressure.getGroundLevelValue() == 222;
|
||||
|
||||
pressure.setSeaLevelValue(4232);
|
||||
assert pressure.getSeaLevelValue() == 4232;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final String pressureString = new Pressure(44).toString();
|
||||
assert pressureString != null;
|
||||
assert !"".equals(pressureString);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreatePressureByConstructorWithInvalidDataNegative_thenThrowAnException() {
|
||||
new Pressure(-33);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreatePressureAndSetInvalidDataNegative_thenThrowAnException() {
|
||||
Pressure pressure = new Pressure(88);
|
||||
pressure.setValue(-89);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidSeaLevelPressure_thenThrowAnException() {
|
||||
Pressure pressure = new Pressure(88);
|
||||
pressure.setSeaLevelValue(-89);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidGroundLevelPressure_thenThrowAnException() {
|
||||
Pressure pressure = new Pressure(88);
|
||||
pressure.setGroundLevelValue(-223);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class RainUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateRainWithValidArgs_thenObjectIsCreated() {
|
||||
new Rain(2222.3, 324234.3);
|
||||
new Rain(null, -213123.4);
|
||||
new Rain(-123123.123, null);
|
||||
new Rain(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValues_thenTheyAreSet() {
|
||||
final Rain snow = new Rain(null, null);
|
||||
|
||||
assert snow.getOneHourRainLevel() == null;
|
||||
assert snow.getThreeHourRainLevel() == null;
|
||||
|
||||
snow.setOneHourRainLevel(33.3);
|
||||
assert snow.getOneHourRainLevel() == 33.3;
|
||||
|
||||
snow.setThreeHourRainLevel(55.5);
|
||||
assert snow.getThreeHourRainLevel() == 55.5;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Rain snow = new Rain();
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert "unknown".equals(snow.toString());
|
||||
|
||||
snow.setThreeHourRainLevel(33.5);
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert !"unknown".equals(snow.toString());
|
||||
|
||||
snow.setOneHourRainLevel(22.2);
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert !"unknown".equals(snow.toString());
|
||||
|
||||
snow.setThreeHourRainLevel(null);
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert !"unknown".equals(snow.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallHashCode_thenAllIsFine() {
|
||||
final Rain first = new Rain();
|
||||
final Rain second = new Rain();
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
second.setThreeHourRainLevel(11.0);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
first.setThreeHourRainLevel(11.0);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
first.setOneHourRainLevel(333.2);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
second.setOneHourRainLevel(333.2);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Rain first = new Rain();
|
||||
final Rain second = new Rain();
|
||||
|
||||
assert first.equals(second);
|
||||
assert first.equals(first);
|
||||
assert !first.equals(new Object());
|
||||
|
||||
first.setOneHourRainLevel(0.34);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
second.setOneHourRainLevel(0.34);
|
||||
|
||||
assert first.equals(second);
|
||||
|
||||
second.setThreeHourRainLevel(66.7);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first.setThreeHourRainLevel(66.7);
|
||||
|
||||
assert first.equals(second);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SnowUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateSnowWithValidArgs_ObjectIsCreated() {
|
||||
new Snow(2222.3, 324234.3);
|
||||
new Snow(null, -213123.4);
|
||||
new Snow(-123123.123, null);
|
||||
new Snow(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValues_thenTheyAreSet() {
|
||||
final Snow snow = new Snow(null, null);
|
||||
|
||||
assert snow.getOneHourSnowLevel() == null;
|
||||
assert snow.getThreeHourSnowLevel() == null;
|
||||
|
||||
snow.setOneHourSnowLevel(33.3);
|
||||
assert snow.getOneHourSnowLevel() == 33.3;
|
||||
|
||||
snow.setThreeHourSnowLevel(55.5);
|
||||
assert snow.getThreeHourSnowLevel() == 55.5;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Snow snow = new Snow();
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert "unknown".equals(snow.toString());
|
||||
|
||||
snow.setThreeHourSnowLevel(33.5);
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert !"unknown".equals(snow.toString());
|
||||
|
||||
snow.setOneHourSnowLevel(22.2);
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert !"unknown".equals(snow.toString());
|
||||
|
||||
snow.setThreeHourSnowLevel(null);
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert !"unknown".equals(snow.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void RainwhenCallHashCode_thenAllIsFine() {
|
||||
final Snow first = new Snow();
|
||||
final Snow second = new Snow();
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
second.setThreeHourSnowLevel(11.0);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
first.setThreeHourSnowLevel(11.0);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
first.setOneHourSnowLevel(333.2);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
second.setOneHourSnowLevel(333.2);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Snow first = new Snow();
|
||||
final Snow second = new Snow();
|
||||
|
||||
assert first.equals(second);
|
||||
assert first.equals(first);
|
||||
assert !first.equals(new Object());
|
||||
|
||||
first.setOneHourSnowLevel(0.34);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
second.setOneHourSnowLevel(0.34);
|
||||
|
||||
assert first.equals(second);
|
||||
|
||||
second.setThreeHourSnowLevel(66.7);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first.setThreeHourSnowLevel(66.7);
|
||||
|
||||
assert first.equals(second);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,121 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TemperatureUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||
new Temperature(22.2, "K");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithEmptyUnit_thenThrowAnException() {
|
||||
new Temperature(22.2, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValue_thenAllIsFine() {
|
||||
final Temperature temperature = new Temperature(22.2, "K");
|
||||
temperature.setValue(55.44);
|
||||
|
||||
assert temperature.getValue() == 55.44;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetMaximumTemperature_thenAllIsOk() {
|
||||
final Temperature temperature = new Temperature(22.2, "K");
|
||||
temperature.setMaxTemperature(44.4);
|
||||
|
||||
assert temperature.getMaxTemperature() == 44.4;
|
||||
|
||||
temperature.setMaxTemperature(null);
|
||||
|
||||
assert temperature.getMaxTemperature() == null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetMinimumTemperature_thenAllIsOk() {
|
||||
final Temperature temperature = new Temperature(22.2, "K");
|
||||
temperature.setMinTemperature(33.2);
|
||||
|
||||
assert temperature.getMinTemperature() == 33.2;
|
||||
|
||||
temperature.setMinTemperature(null);
|
||||
|
||||
assert temperature.getMinTemperature() == null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetNonNullUnit_thenAllIsOk() {
|
||||
final Temperature temperature = new Temperature(22.2, "K");
|
||||
temperature.setUnit("test");
|
||||
|
||||
assert "test".equals(temperature.getUnit());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetNullUnit_thenThrowAnException() {
|
||||
final Temperature temperature = new Temperature(22.2, "K");
|
||||
|
||||
temperature.setUnit(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Temperature temperature = new Temperature(22.2, "K");
|
||||
|
||||
assert !"".equals(temperature.toString());
|
||||
|
||||
temperature.setMinTemperature(11.2);
|
||||
|
||||
assert !"".equals(temperature.toString());
|
||||
|
||||
temperature.setMaxTemperature(44.3);
|
||||
|
||||
assert !"".equals(temperature.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallHashCode_thenAllIsFine() {
|
||||
final Temperature one = new Temperature(22.2, "K");
|
||||
final Temperature two = new Temperature(22.2, "K");
|
||||
|
||||
assert one.hashCode() == two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Temperature one = new Temperature(22.2, "K");
|
||||
final Temperature two = new Temperature(21.2, "K");
|
||||
|
||||
assert one.equals(one);
|
||||
assert !one.equals(new Object());
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
one.setValue(21.2);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setMaxTemperature(33.56);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setMaxTemperature(33.56);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setMinTemperature(11.54);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setMinTemperature(11.54);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
two.setUnit("U");
|
||||
|
||||
assert !one.equals(two);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,287 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class WeatherUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||
new Weather("state", "desc");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithoutState_thenThrowAnException() {
|
||||
new Weather(null, "desc");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithoutDescription_thenThrowAnException() {
|
||||
new Weather("state", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetState_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
weather.setState("test");
|
||||
|
||||
assert "test".equals(weather.getState());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetNullState_thenThrowAnException() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
weather.setState(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetDescription_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
weather.setDescription("test");
|
||||
|
||||
assert "test".equals(weather.getDescription());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetNullDescription_thenThrowAnException() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
weather.setDescription(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetIconUrl_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
weather.setWeatherIconUrl("test");
|
||||
|
||||
assert "test".equals(weather.getWeatherIconUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetRequestedOn_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
weather.setRequestedOn(now);
|
||||
|
||||
assert now.equals(weather.getRequestedOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetTemperature_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Temperature temperature = new Temperature(22.3, "a");
|
||||
weather.setTemperature(temperature);
|
||||
|
||||
assert temperature.equals(weather.getTemperature());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetPressure_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Pressure pressure = new Pressure(33.2);
|
||||
weather.setPressure(pressure);
|
||||
|
||||
assert pressure.equals(weather.getPressure());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetHumidity_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Humidity humidity = new Humidity((byte) 44);
|
||||
weather.setHumidity(humidity);
|
||||
|
||||
assert humidity.equals(weather.getHumidity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetWind_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Wind wind = new Wind(22.2, "a");
|
||||
weather.setWind(wind);
|
||||
|
||||
assert wind.equals(weather.getWind());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetRain_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Rain rain = new Rain();
|
||||
weather.setRain(rain);
|
||||
|
||||
assert rain.equals(weather.getRain());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetSnow_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Snow snow = new Snow();
|
||||
weather.setSnow(snow);
|
||||
|
||||
assert snow.equals(weather.getSnow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetClouds_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Clouds clouds = new Clouds((byte) 33);
|
||||
weather.setClouds(clouds);
|
||||
|
||||
assert clouds.equals(weather.getClouds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetLocation_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Location location = new Location(22, "asd");
|
||||
weather.setLocation(location);
|
||||
|
||||
assert location.equals(weather.getLocation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Location location = new Location(12312, "asd");
|
||||
final Temperature temperature = new Temperature(33.2, "asd");
|
||||
final Pressure pressure = new Pressure(44.4);
|
||||
final Clouds clouds = new Clouds((byte) 55);
|
||||
final Rain rain = new Rain(33.2, null);
|
||||
final Snow snow = new Snow(33.1, null);
|
||||
|
||||
assert !"".equals(weather.toString());
|
||||
weather.setLocation(location);
|
||||
assert !"".equals(weather.toString());
|
||||
location.setCountryCode("3d");
|
||||
assert !"".equals(weather.toString());
|
||||
weather.setTemperature(temperature);
|
||||
assert !"".equals(weather.toString());
|
||||
weather.setPressure(pressure);
|
||||
assert !"".equals(weather.toString());
|
||||
weather.setClouds(clouds);
|
||||
assert !"".equals(weather.toString());
|
||||
weather.setRain(rain);
|
||||
assert !"".equals(weather.toString());
|
||||
weather.setSnow(snow);
|
||||
assert !"".equals(weather.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallHashCode_thenAllIsFine() {
|
||||
final Weather one = new Weather("state", "desc");
|
||||
final Weather two = new Weather("state", "desc");
|
||||
|
||||
assert one.hashCode() == two.hashCode();
|
||||
|
||||
two.setDescription("112");
|
||||
|
||||
assert one.hashCode() != two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Weather one = new Weather("state", "desc");
|
||||
final Weather two = new Weather("state1", "desc1");
|
||||
|
||||
assert one.equals(one);
|
||||
assert !one.equals(new Object());
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setState("state");
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setDescription("desc");
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setWeatherIconUrl("1");
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setWeatherIconUrl("1");
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
one.setRequestedOn(now);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setRequestedOn(now);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Temperature temperature = new Temperature(33.2, "as");
|
||||
one.setTemperature(temperature);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setTemperature(temperature);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Pressure pressure = new Pressure(33.33);
|
||||
one.setPressure(pressure);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setPressure(pressure);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Humidity humidity = new Humidity((byte) 33);
|
||||
one.setHumidity(humidity);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setHumidity(humidity);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Wind wind = new Wind(33.6, "asd");
|
||||
one.setWind(wind);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setWind(wind);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Rain rain = new Rain();
|
||||
one.setRain(rain);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setRain(rain);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Snow snow = new Snow();
|
||||
one.setSnow(snow);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setSnow(snow);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Clouds clouds = new Clouds((byte) 33);
|
||||
one.setClouds(clouds);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setClouds(clouds);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Location location = new Location(231, "asda");
|
||||
one.setLocation(location);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setLocation(location);
|
||||
|
||||
assert one.equals(two);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,157 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class WindUnitTest {
|
||||
@Test
|
||||
public void whenCreateWindWithValidArgs_thenValueIsSet() {
|
||||
assert new Wind(44, "ms").getSpeed() == 44.0;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateWindWithInvalidSpeedArg_thenThrowAnException() {
|
||||
new Wind(-21, "a");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateWindWithInvalidUnitArg_thenThrowAnException() {
|
||||
new Wind(342, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValidSpeed_thenValueIsSet() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
|
||||
assert wind.getSpeed() == 33;
|
||||
|
||||
wind.setSpeed(0);
|
||||
|
||||
assert wind.getSpeed() == 0;
|
||||
|
||||
wind.setSpeed(3656);
|
||||
|
||||
assert wind.getSpeed() == 3656;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidSpeedBelow0_thenThrowAnException() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
|
||||
assert wind.getSpeed() == 33;
|
||||
|
||||
wind.setSpeed(-22);
|
||||
|
||||
assert false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValidDegrees_thenValueIsSet() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
|
||||
assert wind.getDegrees() == null;
|
||||
|
||||
wind.setDegrees(22);
|
||||
|
||||
assert wind.getDegrees() == 22;
|
||||
|
||||
wind.setDegrees(0);
|
||||
|
||||
assert wind.getDegrees() == 0;
|
||||
|
||||
wind.setDegrees(360);
|
||||
|
||||
assert wind.getDegrees() == 360;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidDegreesBelow0_thenThrowAnException() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
wind.setDegrees(-32);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidDegreesAbove360_thenThrowAnException() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
wind.setDegrees(378);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetNonNullUnit_thenValueIsSet() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
|
||||
assert "as".equals(wind.getUnit());
|
||||
|
||||
wind.setUnit("myUnit");
|
||||
|
||||
assert "myUnit".equals(wind.getUnit());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetNullUnit_thenThrowAnException() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
|
||||
wind.setUnit(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Wind wind = new Wind(302, "a");
|
||||
|
||||
assert wind.toString() != null;
|
||||
|
||||
wind.setDegrees(22);
|
||||
|
||||
assert wind.toString() != null && !"".equals(wind.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void RainwhenCallHashCode_thenAllIsFine() {
|
||||
final Wind first = new Wind(22, "a");
|
||||
final Wind second = new Wind(22, "b");
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
second.setUnit("a");
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
second.setSpeed(33);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
first.setSpeed(333);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
first.setSpeed(33);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Wind first = new Wind(11, "a");
|
||||
final Wind second = new Wind(11, "a");
|
||||
|
||||
assert first.equals(second);
|
||||
assert first.equals(first);
|
||||
assert !first.equals(new Object());
|
||||
|
||||
first.setDegrees(34);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
second.setDegrees(34);
|
||||
|
||||
assert first.equals(second);
|
||||
|
||||
second.setUnit("v");
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first.setUnit("v");
|
||||
first.setSpeed(second.getSpeed() + 4);
|
||||
|
||||
assert !first.equals(second);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.github.prominence.openweathermap.api.utils;
|
||||
|
||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RequestUtilsUnitTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenPassInvalidUrl_thenThrowAnException() {
|
||||
RequestUtils.getResponse("wrongUrl");
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenPassUrlToNonExistingPage_thenThrowAnException() {
|
||||
RequestUtils.getResponse("https://openweathermap.org/somePage");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user