A lot of refactoring and documentation writing.

This commit is contained in:
Alexey Zinchenko 2021-03-26 00:48:39 +03:00
parent b301d93b39
commit 64e02cd7a8
86 changed files with 2024 additions and 740 deletions

View File

@ -245,7 +245,7 @@ A forecast for Minsk with 15 timestamps.
|----------------------|------------------------------------------------|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow) |
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
### Dependencies
* com.fasterxml.jackson.core:jackson-databind:2.12.2

View File

@ -30,18 +30,34 @@ import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRe
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.*;
/**
* The main public API client to communicate with OpenWeatherMap services.
* Requires API key for usage. More info on the website <a href="https://openweathermap.org/api">https://openweathermap.org/api</a>.
*/
public class OpenWeatherMapClient {
private final String apiKey;
/**
* Created OpenWeatherMap client object.
* @param apiKey API key obtained on <a href="https://home.openweathermap.org/api_keys">OpwnWeatherMap site</a>.
*/
public OpenWeatherMapClient(String apiKey) {
this.apiKey = apiKey;
}
/**
* Current Weather <a href="https://openweathermap.org/current">API</a>.
* @return requester for retrieving current weather information.
*/
@SubscriptionAvailability(plans = ALL)
public CurrentWeatherRequester currentWeather() {
return new CurrentWeatherRequesterImpl(apiKey);
}
/**
* 5 Day / 3 Hour Forecast <a href="https://openweathermap.org/forecast5">API</a>.
* @return requester for retrieving 5 day/3-hour weather forecast information.
*/
@SubscriptionAvailability(plans = ALL)
public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() {
return new FiveDayThreeHourStepForecastRequesterImpl(apiKey);

View File

@ -35,5 +35,9 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
public @interface SubscriptionAvailability {
/**
* Marks method with subscription plan it needs to have to use the method.
* @return subscription plan.
*/
SubscriptionPlan[] plans();
}

View File

@ -27,38 +27,169 @@ package com.github.prominence.openweathermap.api.enums;
* Usually it could be specified to get response with some fields translated into desired language.
*/
public enum Language {
/**
* Arabic language.
*/
ARABIC("ar"),
/**
* Bulgarian language.
*/
BULGARIAN("bg"),
/**
* Catalan language.
*/
CATALAN("ca"),
/**
* Czech language.
*/
CZECH("cz"),
/**
* German language.
*/
GERMAN("de"),
/**
* Greek language.
*/
GREEK("el"),
/**
* English language.
*/
ENGLISH("en"),
/**
* Persian language.
*/
PERSIAN("fa"),
/**
* Finnish language.
*/
FINNISH("fi"),
/**
* French language.
*/
FRENCH("fr"),
/**
* Galician language.
*/
GALICIAN("gl"),
/**
* Croatian language.
*/
CROATIAN("hr"),
/**
* Hungarian language.
*/
HUNGARIAN("hu"),
/**
* Italian language.
*/
ITALIAN("it"),
/**
* Japanese language.
*/
JAPANESE("ja"),
/**
* Korean language.
*/
KOREAN("kr"),
/**
* Latvian language.
*/
LATVIAN("la"),
/**
* Lithuanian language.
*/
LITHUANIAN("lt"),
/**
* Macedonian language.
*/
MACEDONIAN("mk"),
/**
* Dutch language.
*/
DUTCH("nl"),
/**
* Polish language.
*/
POLISH("pl"),
/**
* Portuguese language.
*/
PORTUGUESE("pt"),
/**
* Romanian language.
*/
ROMANIAN ("ro"),
/**
* Russian language.
*/
RUSSIAN("ru"),
/**
* Swedish language.
*/
SWEDISH("se"),
/**
* Slovak language.
*/
SLOVAK("sk"),
/**
* Slovenian language.
*/
SLOVENIAN("sl"),
/**
* Spanish language.
*/
SPANISH("en"),
/**
* Turkish language.
*/
TURKISH("tr"),
/**
* Ukranian language.
*/
UKRANIAN("uk"),
/**
* Vietnamese language.
*/
VIETNAMESE("vi"),
/**
* Chinese simplified language.
*/
CHINESE_SIMPLIFIED("zh_cn"),
/**
* Chinese traditional language.
*/
CHINESE_TRADITIONAL("zh_tw");
private final String value;
@ -67,6 +198,10 @@ public enum Language {
this.value = value;
}
/**
* Returns language's value.
* @return value.
*/
public String getValue() {
return value;
}

View File

@ -27,10 +27,33 @@ package com.github.prominence.openweathermap.api.enums;
* More information <a href="https://openweathermap.org/price">at official website</a>.
*/
public enum SubscriptionPlan {
/**
* Free subscription plan.
*/
FREE,
/**
* Startup subscription plan.
*/
STARTUP,
/**
* Developer subscription plan.
*/
DEVELOPER,
/**
* Professional subscription plan.
*/
PROFESSIONAL,
/**
* Enterprise subscription plan.
*/
ENTERPRISE,
/**
* All existing subscription plans.
*/
ALL,
}

View File

@ -26,8 +26,19 @@ package com.github.prominence.openweathermap.api.enums;
* An enumeration for supported unit systems with helper methods.
*/
public enum UnitSystem {
/**
* Metric units: Celsius, meter/sec, hPa, mm(rain, snow).
*/
METRIC("metric"),
/**
* Imperial units: Fahrenheit, miles/hour, hPa, mm(rain, snow).
*/
IMPERIAL("imperial"),
/**
* OpenWeatherMap standard units: Kelvin, meter/sec, hPa, mm(rain, snow).
*/
STANDARD("standard");
private final String value;
@ -36,6 +47,10 @@ public enum UnitSystem {
this.value = value;
}
/**
* Returns wind unit for current unit system.
* @return wind unit.
*/
public String getWindUnit() {
switch (this) {
case IMPERIAL:
@ -47,6 +62,10 @@ public enum UnitSystem {
}
}
/**
* Returns temperature unit for current unit system.
* @return temperature unit.
*/
public String getTemperatureUnit() {
switch (this) {
case METRIC:
@ -59,6 +78,10 @@ public enum UnitSystem {
}
}
/**
* Returns unit system value.
* @return value unit system.
*/
public String getValue() {
return value;
}

View File

@ -28,6 +28,9 @@ package com.github.prominence.openweathermap.api.exception;
* API Keys could be checked in <a href="https://home.openweathermap.org/api_keys/">your profile</a>.
*/
public class InvalidAuthTokenException extends RuntimeException {
/**
* Creates {@link InvalidAuthTokenException} exception with default message.
*/
public InvalidAuthTokenException() {
super("Authentication token wasn't set or requested functionality is not permitted for your subscription plan. Please, check https://home.openweathermap.org/api_keys/ and https://openweathermap.org/price.");
}

View File

@ -31,10 +31,17 @@ package com.github.prominence.openweathermap.api.exception;
* </ul>
*/
public class NoDataFoundException extends RuntimeException {
/**
* Creates {@link NoDataFoundException} with default message.
*/
public NoDataFoundException() {
super("Data for provided parameters wasn't found. Please, check requested location.");
}
/**
* Creates {@link NoDataFoundException} with message from another throwable.
* @param throwable source throwable.
*/
public NoDataFoundException(Throwable throwable) {
super(throwable.getMessage(), throwable.getCause());
}

View File

@ -29,7 +29,6 @@ import java.util.Objects;
* Its value can only be a double in [0, +) range.
*/
public class AtmosphericPressure {
private static final String DEFAULT_UNIT = "hPa";
private double value;
@ -47,7 +46,12 @@ public class AtmosphericPressure {
this.value = value;
}
public static AtmosphericPressure forValue(double value) {
/**
* Static method for {@link AtmosphericPressure} creation with value checking.
* @param value atmospheric pressure value.
* @return instantiated {@link AtmosphericPressure} object.
*/
public static AtmosphericPressure withValue(double value) {
if (value < 0) {
throw new IllegalArgumentException("Atmospheric pressure value must be in [0, +∞) range.");
}

View File

@ -29,7 +29,6 @@ import java.util.Objects;
* Its value can only be an integer in [0, 100] range.
*/
public class Clouds {
private static final String DEFAULT_UNIT = "%";
private byte value;
@ -44,7 +43,12 @@ public class Clouds {
this.value = value;
}
public static Clouds forValue(byte value) {
/**
* Static method for {@link Clouds} creation with value checking.
* @param value clouds percentage value.
* @return instantiated {@link Clouds} object.
*/
public static Clouds withValue(byte value) {
if (value < 0 || value > 100) {
throw new IllegalArgumentException("Cloudiness value must be in [0, 100] range.");
}

View File

@ -24,6 +24,9 @@ package com.github.prominence.openweathermap.api.model;
import java.util.Objects;
/**
* Represents some location by its latitude and longitude.
*/
public class Coordinate {
private double latitude;
private double longitude;
@ -33,7 +36,13 @@ public class Coordinate {
this.longitude = longitude;
}
public static Coordinate forValues(double latitude, double longitude) {
/**
* Method for {@link Coordinate} creation with correctness check.
* @param latitude latitude
* @param longitude longitude
* @return coordinate object.
*/
public static Coordinate withValues(double latitude, double longitude) {
if (latitude < -90 || latitude > 90) {
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
}
@ -43,6 +52,10 @@ public class Coordinate {
return new Coordinate(latitude, longitude);
}
/**
* Sets latitude with checks.
* @param latitude latitude value
*/
public void setLatitude(double latitude) {
if (latitude < -90 || latitude > 90) {
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
@ -50,6 +63,10 @@ public class Coordinate {
this.latitude = latitude;
}
/**
* Sets longitude with checks.
* @param longitude longitude value
*/
public void setLongitude(double longitude) {
if (longitude < -180 || longitude > 180) {
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
@ -57,10 +74,18 @@ public class Coordinate {
this.longitude = longitude;
}
/**
* Returns latitude.
* @return latitude
*/
public double getLatitude() {
return latitude;
}
/**
* Returns longitude.
* @return longitude
*/
public double getLongitude() {
return longitude;
}

View File

@ -24,9 +24,10 @@ package com.github.prominence.openweathermap.api.model;
import java.util.Objects;
// TODO: builder?
/**
* Represents coordinate rectangle by its bottom-left and top-right coordinates.
*/
public class CoordinateRectangle {
private final double longitudeLeft;
private final double latitudeBottom;
private final double longitudeRight;
@ -39,7 +40,15 @@ public class CoordinateRectangle {
this.latitudeTop = latitudeTop;
}
public static CoordinateRectangle forValues(double longitudeLeft, double latitudeBottom, double longitudeRight, double latitudeTop) {
/**
* Method for {@link CoordinateRectangle} creation with correctness check.
* @param longitudeLeft left longitude
* @param latitudeBottom bottom latitude
* @param longitudeRight right longitude
* @param latitudeTop tip latitude
* @return coordinate rectangle object.
*/
public static CoordinateRectangle withValues(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].");
}
@ -49,22 +58,42 @@ public class CoordinateRectangle {
return new CoordinateRectangle(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop);
}
/**
* Returns left longitude value.
* @return left longitude
*/
public double getLongitudeLeft() {
return longitudeLeft;
}
/**
* Returns bottom latitude value.
* @return bottom latitude
*/
public double getLatitudeBottom() {
return latitudeBottom;
}
/**
* Returns right longitude value.
* @return right longitude
*/
public double getLongitudeRight() {
return longitudeRight;
}
/**
* Returns top latitude value.
* @return top latitude
*/
public double getLatitudeTop() {
return latitudeTop;
}
/**
* Formatted coordinate rectangle string.
* @return formatted string
*/
public String getFormattedRequestString() {
return longitudeLeft + "," + latitudeBottom + "," + longitudeRight + "," + latitudeTop;
}
@ -89,4 +118,83 @@ public class CoordinateRectangle {
public String toString() {
return "Rectangle: " + getFormattedRequestString();
}
/**
* Builder for CoordinateRectangle class.
*/
public static class Builder {
private Double longitudeLeft;
private Double latitudeBottom;
private Double longitudeRight;
private Double latitudeTop;
/**
* Creates Builder object.
*/
public Builder() {
}
/**
* Sets left longitude with correctness check.
* @param longitudeLeft left longitude
* @return builder object
*/
public Builder setLongitudeLeft(double longitudeLeft) {
if (longitudeLeft < -180 || longitudeLeft > 180) {
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
}
this.longitudeLeft = longitudeLeft;
return this;
}
/**
* Sets bottom latitude with correctness check.
* @param latitudeBottom bottom latitude
* @return builder object
*/
public Builder setLatitudeBottom(double latitudeBottom) {
if (latitudeBottom < -90 || latitudeBottom > 90) {
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
}
this.latitudeBottom = latitudeBottom;
return this;
}
/**
* Sets right longitude with correctness check.
* @param longitudeRight right longitude
* @return builder object
*/
public Builder setLongitudeRight(double longitudeRight) {
if (longitudeRight < -180 || longitudeRight > 180) {
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
}
this.longitudeRight = longitudeRight;
return this;
}
/**
* Sets top latitude with correctness check.
* @param latitudeTop top latitude
* @return builder object
*/
public Builder setLatitudeTop(double latitudeTop) {
if (latitudeTop < -90 || latitudeTop > 90) {
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
}
this.latitudeTop = latitudeTop;
return this;
}
/**
* Builds {@link CoordinateRectangle} object with correctness check.
* @return {@link CoordinateRectangle} built object.
*/
public CoordinateRectangle build() {
if (longitudeLeft == null || latitudeBottom == null || longitudeRight == null || latitudeTop == null) {
throw new IllegalStateException("Not all fields were set.");
}
return new CoordinateRectangle(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop);
}
}
}

View File

@ -22,8 +22,18 @@
package com.github.prominence.openweathermap.api.model;
/**
* Enumeration for time of a day representation.
*/
public enum DayTime {
/**
* Day value.
*/
DAY("d"),
/**
* Night value.
*/
NIGHT("n");
private final String value;
@ -32,6 +42,10 @@ public enum DayTime {
this.value = value;
}
/**
* Returns time of a day value.
* @return string value
*/
public String getValue() {
return value;
}

View File

@ -29,7 +29,6 @@ import java.util.Objects;
* Its value can only be an integer in [0, 100] range.
*/
public class Humidity {
private static final String DEFAULT_UNIT = "%";
private int value;
@ -44,7 +43,12 @@ public class Humidity {
this.value = value;
}
public static Humidity forValue(byte value) {
/**
* Creates {@link Humidity} object with correctness check.
* @param value humidity
* @return created {@link Humidity} object
*/
public static Humidity withValue(byte value) {
if (value < 0 || value > 100) {
throw new IllegalArgumentException("Humidity value must be in [0, 100] range.");
}

View File

@ -24,6 +24,9 @@ package com.github.prominence.openweathermap.api.model;
import java.util.Objects;
/**
* Represents temperature values and unit.
*/
public class Temperature {
private double value;
private Double maxTemperature;
@ -36,49 +39,95 @@ public class Temperature {
this.unit = unit;
}
public static Temperature forValue(double value, String unit) {
/**
* Creates {@link Temperature} object with correctness check.
* @param value temperature value
* @param unit temperature unit
* @return temperature object
*/
public static Temperature withValue(double value, String unit) {
if (unit == null) {
throw new IllegalArgumentException("Unit must be set.");
}
return new Temperature(value, unit);
}
/**
* Returns temperature value.
* @return value
*/
public double getValue() {
return value;
}
/**
* Sets temperature value.
* @param value temperature
*/
public void setValue(double value) {
this.value = value;
}
/**
* Returns maximal temperature value.
* @return maximal temperature value
*/
public Double getMaxTemperature() {
return maxTemperature;
}
/**
* Sets maximal temperature value.
* @param maxTemperature maximal temperature
*/
public void setMaxTemperature(Double maxTemperature) {
this.maxTemperature = maxTemperature;
}
/**
* Returns minimal temperature value.
* @return minimal temperature value
*/
public Double getMinTemperature() {
return minTemperature;
}
/**
* Sets minimal temperature value.
* @param minTemperature minimal temperature
*/
public void setMinTemperature(Double minTemperature) {
this.minTemperature = minTemperature;
}
/**
* Returns 'feels like' temperature value.
* @return 'feels like' temperature value
*/
public Double getFeelsLike() {
return feelsLike;
}
/**
* Sets 'feels like' temperature value.
* @param feelsLike 'feels like' temperature
*/
public void setFeelsLike(Double feelsLike) {
this.feelsLike = feelsLike;
}
/**
* Returns temperature unit.
* @return unit
*/
public String getUnit() {
return unit;
}
/**
* Sets temperature unit with correctness check.
* @param unit temperature unit
*/
public void setUnit(String unit) {
if (unit == null) {
throw new IllegalArgumentException("Unit must be set.");

View File

@ -20,49 +20,46 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 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.model.forecast;
import java.util.List;
import java.util.Objects;
/**
* Represents information about forecast for different timestamps.
*/
public class Forecast {
private Location location;
private List<WeatherForecast> weatherForecasts;
/**
* Returns location information.
* @return location
*/
public Location getLocation() {
return location;
}
/**
* Sets forecast location.
* @param location forecast location
*/
public void setLocation(Location location) {
this.location = location;
}
/**
* Returns list of weather forecasts for different timestamps.
* @return list of forecast-per-timestamp information.
*/
public List<WeatherForecast> getWeatherForecasts() {
return weatherForecasts;
}
/**
* Sets list of weather forecasts for different timestamps.
* @param weatherForecasts list of forecast information
*/
public void setWeatherForecasts(List<WeatherForecast> weatherForecasts) {
this.weatherForecasts = weatherForecasts;
}

View File

@ -28,8 +28,10 @@ import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Objects;
/**
* Represents location information.
*/
public class Location {
private int id;
private String name;
private String countryCode;
@ -47,73 +49,143 @@ public class Location {
this.name = name;
}
public static Location forValue(int id, String name) {
/**
* Creates {@link Location} object with correctness check.
* @param id location id
* @param name location name
* @return location object
*/
public static Location withValues(int id, String name) {
if (name == null) {
throw new IllegalArgumentException("Name must be set.");
}
return new Location(id, name);
}
/**
* Returns ID.
* @return location ID
*/
public int getId() {
return id;
}
/**
* Sets location ID.
* @param id location id
*/
public void setId(int id) {
this.id = id;
}
/**
* Returns location name.
* @return location name
*/
public String getName() {
return name;
}
/**
* Sets location name.
* @param name location name
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns country code.
* @return location country code
*/
public String getCountryCode() {
return countryCode;
}
/**
* Sets location country code.
* @param countryCode location country code
*/
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
/**
* Returns location sunrise time.
* @return sunrise time
*/
public LocalDateTime getSunrise() {
return sunrise;
}
/**
* Sets location sunrise time.
* @param sunrise sunrise time
*/
public void setSunrise(LocalDateTime sunrise) {
this.sunrise = sunrise;
}
/**
* Returns location sunset time.
* @return sunset time
*/
public LocalDateTime getSunset() {
return sunset;
}
/**
* Sets location sunset time.
* @param sunset sunset time
*/
public void setSunset(LocalDateTime sunset) {
this.sunset = sunset;
}
/**
* Returns location timezone offset.
* @return timezone offset
*/
public ZoneOffset getZoneOffset() {
return zoneOffset;
}
/**
* Sets location timezone offset.
* @param zoneOffset timezone offset
*/
public void setZoneOffset(ZoneOffset zoneOffset) {
this.zoneOffset = zoneOffset;
}
/**
* Returns location coordinates.
* @return location coordinates.
*/
public Coordinate getCoordinate() {
return coordinate;
}
/**
* Sets location coordinates.
* @param coordinate location coordinates
*/
public void setCoordinate(Coordinate coordinate) {
this.coordinate = coordinate;
}
/**
* Sets location population.
* @return location population
*/
public Long getPopulation() {
return population;
}
/**
* Sets location population.
* @param population location population
*/
public void setPopulation(Long population) {
this.population = population;
}

View File

@ -24,27 +24,53 @@ package com.github.prominence.openweathermap.api.model.forecast;
import java.util.Objects;
/**
* Represents rain information.
*/
public class Rain {
private static final String DEFAULT_UNIT = "mm";
private Double threeHourRainLevel;
private double threeHourRainLevel;
public Rain() {
}
public Rain(Double threeHourRainLevel) {
private Rain(double threeHourRainLevel) {
this.threeHourRainLevel = threeHourRainLevel;
}
public Double getThreeHourRainLevel() {
/**
* Creates {@link Rain} object with correctness check.
* @param threeHourRainLevel 3-hour rain level value
* @return rain object.
*/
public static Rain withThreeHourLevelValue(double threeHourRainLevel) {
if (threeHourRainLevel < 0) {
throw new IllegalArgumentException("Rain level value cannot be negative.");
}
return new Rain(threeHourRainLevel);
}
/**
* Returns 3-hour rain level value.
* @return 3-hour rain level value
*/
public double getThreeHourRainLevel() {
return threeHourRainLevel;
}
public void setThreeHourRainLevel(Double threeHourRainLevel) {
/**
* Sets 3-hour rain level value with correctness check.
* @param threeHourRainLevel 3-hour rain level value
*/
public void setThreeHourRainLevel(double threeHourRainLevel) {
if (threeHourRainLevel < 0) {
throw new IllegalArgumentException("Rain level value cannot be negative.");
}
this.threeHourRainLevel = threeHourRainLevel;
}
/**
* Returns rain level unit of measure. Currently is constant.
* @return rain level unit of measure
*/
public String getUnit() {
return DEFAULT_UNIT;
}
@ -52,9 +78,9 @@ public class Rain {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Rain)) return false;
if (o == null || getClass() != o.getClass()) return false;
Rain rain = (Rain) o;
return Objects.equals(threeHourRainLevel, rain.threeHourRainLevel);
return Double.compare(rain.threeHourRainLevel, threeHourRainLevel) == 0;
}
@Override
@ -64,14 +90,8 @@ public class Rain {
@Override
public String toString() {
StringBuilder snowString = new StringBuilder();
if (threeHourRainLevel == null) {
snowString.append("unknown");
} else {
snowString.append("3 last hours rain level: ");
snowString.append(threeHourRainLevel);
snowString.append(getUnit());
}
return snowString.toString();
return "3-hour rain level: " +
threeHourRainLevel + ' ' +
getUnit();
}
}

View File

@ -24,26 +24,53 @@ package com.github.prominence.openweathermap.api.model.forecast;
import java.util.Objects;
/**
* Represents snow information.
*/
public class Snow {
private static final String DEFAULT_UNIT = "mm";
private Double threeHourSnowLevel;
private double threeHourSnowLevel;
public Snow() {
}
public Snow(Double threeHourSnowLevel) {
private Snow(double threeHourSnowLevel) {
this.threeHourSnowLevel = threeHourSnowLevel;
}
public Double getThreeHourSnowLevel() {
/**
* Creates {@link Snow} object with correctness check.
* @param threeHourSnowLevel 3-hour snow level value
* @return snow object.
*/
public static Snow withThreeHourLevelValue(double threeHourSnowLevel) {
if (threeHourSnowLevel < 0) {
throw new IllegalArgumentException("Snow level value cannot be negative.");
}
return new Snow(threeHourSnowLevel);
}
/**
* Returns 3-hour snow level value.
* @return 3-hour snow level value
*/
public double getThreeHourSnowLevel() {
return threeHourSnowLevel;
}
public void setThreeHourSnowLevel(Double threeHourSnowLevel) {
/**
* Sets 3-hour snow level value with correctness check.
* @param threeHourSnowLevel 3-hour snow level value
*/
public void setThreeHourSnowLevel(double threeHourSnowLevel) {
if (threeHourSnowLevel < 0) {
throw new IllegalArgumentException("Snow level value cannot be negative.");
}
this.threeHourSnowLevel = threeHourSnowLevel;
}
/**
* Returns snow level unit of measure. Currently is constant.
* @return snow level unit of measure
*/
public String getUnit() {
return DEFAULT_UNIT;
}
@ -51,9 +78,9 @@ public class Snow {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Snow)) return false;
if (o == null || getClass() != o.getClass()) return false;
Snow snow = (Snow) o;
return Objects.equals(threeHourSnowLevel, snow.threeHourSnowLevel);
return Double.compare(snow.threeHourSnowLevel, threeHourSnowLevel) == 0;
}
@Override
@ -63,14 +90,8 @@ public class Snow {
@Override
public String toString() {
StringBuilder snowString = new StringBuilder();
if (threeHourSnowLevel == null) {
snowString.append("unknown");
} else {
snowString.append("3 last hours snow level: ");
snowString.append(threeHourSnowLevel);
snowString.append(getUnit());
}
return snowString.toString();
return "3-hour snow level: " +
threeHourSnowLevel + ' ' +
getUnit();
}
}

View File

@ -27,6 +27,9 @@ import com.github.prominence.openweathermap.api.model.*;
import java.time.LocalDateTime;
import java.util.Objects;
/**
* Represents weather forecast information for a particular timestamp.
*/
public class WeatherForecast {
private String state;
private String description;
@ -51,6 +54,13 @@ public class WeatherForecast {
this.description = description;
}
/**
* For value weather forecast.
*
* @param state the state
* @param description the description
* @return the weather forecast
*/
public static WeatherForecast forValue(String state, String description) {
if (state == null) {
throw new IllegalArgumentException("State must be set.");
@ -61,10 +71,20 @@ public class WeatherForecast {
return new WeatherForecast(state, description);
}
/**
* Gets state.
*
* @return the state
*/
public String getState() {
return state;
}
/**
* Sets state.
*
* @param state the state
*/
public void setState(String state) {
if (state == null) {
throw new IllegalArgumentException("State must be not null.");
@ -72,10 +92,20 @@ public class WeatherForecast {
this.state = state;
}
/**
* Gets description.
*
* @return the description
*/
public String getDescription() {
return description;
}
/**
* Sets description.
*
* @param description the description
*/
public void setDescription(String description) {
if (description == null) {
throw new IllegalArgumentException("Description must be not null.");
@ -83,90 +113,200 @@ public class WeatherForecast {
this.description = description;
}
/**
* Gets weather icon url.
*
* @return the weather icon url
*/
public String getWeatherIconUrl() {
return weatherIconUrl;
}
/**
* Sets weather icon url.
*
* @param weatherIconUrl the weather icon url
*/
public void setWeatherIconUrl(String weatherIconUrl) {
this.weatherIconUrl = weatherIconUrl;
}
/**
* Gets forecast time.
*
* @return the forecast time
*/
public LocalDateTime getForecastTime() {
return forecastTime;
}
/**
* Sets forecast time.
*
* @param forecastTime the forecast time
*/
public void setForecastTime(LocalDateTime forecastTime) {
this.forecastTime = forecastTime;
}
/**
* Gets temperature.
*
* @return the temperature
*/
public Temperature getTemperature() {
return temperature;
}
/**
* Sets temperature.
*
* @param temperature the temperature
*/
public void setTemperature(Temperature temperature) {
this.temperature = temperature;
}
/**
* Gets atmospheric pressure.
*
* @return the atmospheric pressure
*/
public AtmosphericPressure getAtmosphericPressure() {
return atmosphericPressure;
}
/**
* Sets atmospheric pressure.
*
* @param atmosphericPressure the atmospheric pressure
*/
public void setAtmosphericPressure(AtmosphericPressure atmosphericPressure) {
this.atmosphericPressure = atmosphericPressure;
}
/**
* Gets humidity.
*
* @return the humidity
*/
public Humidity getHumidity() {
return humidity;
}
/**
* Sets humidity.
*
* @param humidity the humidity
*/
public void setHumidity(Humidity humidity) {
this.humidity = humidity;
}
/**
* Gets wind.
*
* @return the wind
*/
public Wind getWind() {
return wind;
}
/**
* Sets wind.
*
* @param wind the wind
*/
public void setWind(Wind wind) {
this.wind = wind;
}
/**
* Gets rain.
*
* @return the rain
*/
public Rain getRain() {
return rain;
}
/**
* Sets rain.
*
* @param rain the rain
*/
public void setRain(Rain rain) {
this.rain = rain;
}
/**
* Gets snow.
*
* @return the snow
*/
public Snow getSnow() {
return snow;
}
/**
* Sets snow.
*
* @param snow the snow
*/
public void setSnow(Snow snow) {
this.snow = snow;
}
/**
* Gets clouds.
*
* @return the clouds
*/
public Clouds getClouds() {
return clouds;
}
/**
* Sets clouds.
*
* @param clouds the clouds
*/
public void setClouds(Clouds clouds) {
this.clouds = clouds;
}
/**
* Gets forecast time iso.
*
* @return the forecast time iso
*/
public String getForecastTimeISO() {
return forecastTimeISO;
}
/**
* Sets forecast time iso.
*
* @param forecastTimeISO the forecast time iso
*/
public void setForecastTimeISO(String forecastTimeISO) {
this.forecastTimeISO = forecastTimeISO;
}
/**
* Gets day time.
*
* @return the day time
*/
public DayTime getDayTime() {
return dayTime;
}
/**
* Sets day time.
*
* @param dayTime the day time
*/
public void setDayTime(DayTime dayTime) {
this.dayTime = dayTime;
}
@ -219,13 +359,13 @@ public class WeatherForecast {
stringBuilder.append(", ");
stringBuilder.append(clouds.toString());
}
if (rain != null && rain.getThreeHourRainLevel() != null) {
if (rain != null) {
stringBuilder.append(", Rain: ");
stringBuilder.append(rain.getThreeHourRainLevel());
stringBuilder.append(' ');
stringBuilder.append(rain.getUnit());
}
if (snow != null && snow.getThreeHourSnowLevel() != null) {
if (snow != null) {
stringBuilder.append(", Snow: ");
stringBuilder.append(snow.getThreeHourSnowLevel());
stringBuilder.append(' ');

View File

@ -20,37 +20,14 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 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.model.forecast;
import java.util.Objects;
/**
* The type Wind.
* Represents wind information.
*/
public class Wind {
private double speed;
private Double degrees;
private String unit;
@ -66,7 +43,13 @@ public class Wind {
this.unit = unit;
}
public static Wind forValue(double speed, String unit) {
/**
* Creates {@link Wind} object with correctness check
* @param speed the wind
* @param unit the unitSystem
* @return created wind object
*/
public static Wind withValue(double speed, String unit) {
if (speed < 0) {
throw new IllegalArgumentException("Wind speed value must be in positive or zero.");
}

View File

@ -20,28 +20,6 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 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.model.weather;
import com.github.prominence.openweathermap.api.model.Coordinate;
@ -50,8 +28,10 @@ import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Objects;
/**
* Represents location information.
*/
public class Location {
private int id;
private String name;
private String countryCode;
@ -67,65 +47,127 @@ public class Location {
this.name = name;
}
public static Location forValue(int id, String name) {
/**
* Creates {@link Location} object with correctness check.
* @param id location id
* @param name location name
* @return location object
*/
public static Location withValues(int id, String name) {
if (name == null) {
throw new IllegalArgumentException("Name must be set.");
}
return new Location(id, name);
}
/**
* Returns ID.
* @return location ID
*/
public int getId() {
return id;
}
/**
* Sets location ID.
* @param id location id
*/
public void setId(int id) {
this.id = id;
}
/**
* Returns location name.
* @return location name
*/
public String getName() {
return name;
}
/**
* Sets location name.
* @param name location name
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns country code.
* @return location country code
*/
public String getCountryCode() {
return countryCode;
}
/**
* Sets location country code.
* @param countryCode location country code
*/
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
/**
* Returns location sunrise time.
* @return sunrise time
*/
public LocalDateTime getSunrise() {
return sunrise;
}
/**
* Sets location sunrise time.
* @param sunrise sunrise time
*/
public void setSunrise(LocalDateTime sunrise) {
this.sunrise = sunrise;
}
/**
* Returns location sunset time.
* @return sunset time
*/
public LocalDateTime getSunset() {
return sunset;
}
/**
* Sets location sunset time.
* @param sunset sunset time
*/
public void setSunset(LocalDateTime sunset) {
this.sunset = sunset;
}
/**
* Returns location timezone offset.
* @return timezone offset
*/
public ZoneOffset getZoneOffset() {
return zoneOffset;
}
/**
* Sets location timezone offset.
* @param zoneOffset timezone offset
*/
public void setZoneOffset(ZoneOffset zoneOffset) {
this.zoneOffset = zoneOffset;
}
/**
* Returns location coordinates.
* @return location coordinates.
*/
public Coordinate getCoordinate() {
return coordinate;
}
/**
* Sets location coordinates.
* @param coordinate location coordinates
*/
public void setCoordinate(Coordinate coordinate) {
this.coordinate = coordinate;
}

View File

@ -20,63 +20,107 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 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.model.weather;
import java.util.Objects;
/**
* Represents rain information.
*/
public class Rain {
private static final String DEFAULT_UNIT = "mm";
private Double oneHourRainLevel;
private Double threeHourRainLevel;
public Rain() {
private Rain() {
}
public Rain(Double oneHourRainLevel, Double threeHourRainLevel) {
this.oneHourRainLevel = oneHourRainLevel;
this.threeHourRainLevel = threeHourRainLevel;
/**
* Creates {@link Rain} object with correctness check.
*
* @param oneHourRainLevel 1-hour rain level value
* @return rain object.
*/
public static Rain withOneHourLevelValue(double oneHourRainLevel) {
Rain rain = new Rain();
rain.setOneHourRainLevel(oneHourRainLevel);
return rain;
}
/**
* Creates {@link Rain} object with correctness check.
*
* @param threeHourRainLevel 3-hour rain level value
* @return rain object.
*/
public static Rain withThreeHourLevelValue(double threeHourRainLevel) {
Rain rain = new Rain();
rain.setThreeHourRainLevel(threeHourRainLevel);
return rain;
}
/**
* Creates {@link Rain} object with correctness check.
*
* @param oneHourRainLevel the one hour rain level
* @param threeHourRainLevel the three hour rain level
* @return the rain
*/
public static Rain withValues(double oneHourRainLevel, double threeHourRainLevel) {
Rain rain = new Rain();
rain.setOneHourRainLevel(oneHourRainLevel);
rain.setThreeHourRainLevel(threeHourRainLevel);
return rain;
}
/**
* Gets one hour rain level.
*
* @return the one hour rain level
*/
public Double getOneHourRainLevel() {
return oneHourRainLevel;
}
public void setOneHourRainLevel(Double oneHourRainLevel) {
/**
* Sets one hour rain level.
*
* @param oneHourRainLevel the one hour rain level
*/
public void setOneHourRainLevel(double oneHourRainLevel) {
if (oneHourRainLevel < 0) {
throw new IllegalArgumentException("Rain level value cannot be negative.");
}
this.oneHourRainLevel = oneHourRainLevel;
}
/**
* Gets three hour rain level.
*
* @return the three hour rain level
*/
public Double getThreeHourRainLevel() {
return threeHourRainLevel;
}
public void setThreeHourRainLevel(Double threeHourRainLevel) {
/**
* Sets three hour rain level.
*
* @param threeHourRainLevel the three hour rain level
*/
public void setThreeHourRainLevel(double threeHourRainLevel) {
if (threeHourRainLevel < 0) {
throw new IllegalArgumentException("Rain level value cannot be negative.");
}
this.threeHourRainLevel = threeHourRainLevel;
}
/**
* Gets unit.
*
* @return the unit
*/
public String getUnit() {
return DEFAULT_UNIT;
}
@ -98,22 +142,18 @@ public class Rain {
@Override
public String toString() {
StringBuilder snowString = new StringBuilder();
if (oneHourRainLevel == null && threeHourRainLevel == null) {
snowString.append("unknown");
} else {
if (oneHourRainLevel != null) {
snowString.append("1-hour rain level: ");
snowString.append(oneHourRainLevel);
snowString.append(getUnit());
}
if (threeHourRainLevel != null) {
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());
snowString.append(", ");
}
snowString.append("3-hours rain level: ");
snowString.append(threeHourRainLevel);
snowString.append(getUnit());
}
return snowString.toString();
}

View File

@ -20,63 +20,107 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 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.model.weather;
import java.util.Objects;
/**
* Represents snow information.
*/
public class Snow {
private static final String DEFAULT_UNIT = "mm";
private Double oneHourSnowLevel;
private Double threeHourSnowLevel;
public Snow() {
private Snow() {
}
public Snow(Double oneHourSnowLevel, Double threeHourSnowLevel) {
this.oneHourSnowLevel = oneHourSnowLevel;
this.threeHourSnowLevel = threeHourSnowLevel;
/**
* Creates {@link Snow} object with correctness check.
*
* @param oneHourSnowLevel 1-hour snow level value
* @return snow object.
*/
public static Snow withOneHourLevelValue(double oneHourSnowLevel) {
Snow snow = new Snow();
snow.setOneHourSnowLevel(oneHourSnowLevel);
return snow;
}
/**
* Creates {@link Snow} object with correctness check.
*
* @param threeHourSnowLevel 3-hour snow level value
* @return snow object.
*/
public static Snow withThreeHourLevelValue(double threeHourSnowLevel) {
Snow snow = new Snow();
snow.setThreeHourSnowLevel(threeHourSnowLevel);
return snow;
}
/**
* Creates {@link Snow} object with correctness check.
*
* @param oneHourSnowLevel the one hour snow level
* @param threeHourSnowLevel the three hour snow level
* @return the snow
*/
public static Snow withValues(double oneHourSnowLevel, double threeHourSnowLevel) {
Snow snow = new Snow();
snow.setOneHourSnowLevel(oneHourSnowLevel);
snow.setThreeHourSnowLevel(threeHourSnowLevel);
return snow;
}
/**
* Gets one hour snow level.
*
* @return the one hour snow level
*/
public Double getOneHourSnowLevel() {
return oneHourSnowLevel;
}
public void setOneHourSnowLevel(Double oneHourSnowLevel) {
/**
* Sets one hour snow level.
*
* @param oneHourSnowLevel the one hour snow level
*/
public void setOneHourSnowLevel(double oneHourSnowLevel) {
if (oneHourSnowLevel < 0) {
throw new IllegalArgumentException("Snow level value cannot be negative.");
}
this.oneHourSnowLevel = oneHourSnowLevel;
}
/**
* Gets three hour snow level.
*
* @return the three hour snow level
*/
public Double getThreeHourSnowLevel() {
return threeHourSnowLevel;
}
public void setThreeHourSnowLevel(Double threeHourSnowLevel) {
/**
* Sets three hour snow level.
*
* @param threeHourSnowLevel the three hour snow level
*/
public void setThreeHourSnowLevel(double threeHourSnowLevel) {
if (threeHourSnowLevel < 0) {
throw new IllegalArgumentException("Snow level value cannot be negative.");
}
this.threeHourSnowLevel = threeHourSnowLevel;
}
/**
* Gets unit.
*
* @return the unit
*/
public String getUnit() {
return DEFAULT_UNIT;
}
@ -98,22 +142,18 @@ public class Snow {
@Override
public String toString() {
StringBuilder snowString = new StringBuilder();
if (oneHourSnowLevel == null && threeHourSnowLevel == null) {
snowString.append("unknown");
} else {
if (oneHourSnowLevel != null) {
snowString.append("1-hour snow level: ");
snowString.append(oneHourSnowLevel);
snowString.append(getUnit());
}
if (threeHourSnowLevel != null) {
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());
snowString.append(", ");
}
snowString.append("3-hours snow level: ");
snowString.append(threeHourSnowLevel);
snowString.append(getUnit());
}
return snowString.toString();
}

View File

@ -20,28 +20,6 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 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.model.weather;
import com.github.prominence.openweathermap.api.model.*;
@ -49,6 +27,9 @@ import com.github.prominence.openweathermap.api.model.*;
import java.time.LocalDateTime;
import java.util.Objects;
/**
* Represents weather information.
*/
public class Weather {
private String state;
private String description;
@ -72,6 +53,13 @@ public class Weather {
this.description = description;
}
/**
* For value weather.
*
* @param state the state
* @param description the description
* @return the weather
*/
public static Weather forValue(String state, String description) {
if (state == null) {
throw new IllegalArgumentException("State must be set.");
@ -82,10 +70,20 @@ public class Weather {
return new Weather(state, description);
}
/**
* Gets state.
*
* @return the state
*/
public String getState() {
return state;
}
/**
* Sets state.
*
* @param state the state
*/
public void setState(String state) {
if (state == null) {
throw new IllegalArgumentException("State must be set.");
@ -93,10 +91,20 @@ public class Weather {
this.state = state;
}
/**
* Gets description.
*
* @return the description
*/
public String getDescription() {
return description;
}
/**
* Sets description.
*
* @param description the description
*/
public void setDescription(String description) {
if (description == null) {
throw new IllegalArgumentException("Description must be set.");
@ -104,82 +112,182 @@ public class Weather {
this.description = description;
}
/**
* Gets weather icon url.
*
* @return the weather icon url
*/
public String getWeatherIconUrl() {
return weatherIconUrl;
}
/**
* Sets weather icon url.
*
* @param weatherIconUrl the weather icon url
*/
public void setWeatherIconUrl(String weatherIconUrl) {
this.weatherIconUrl = weatherIconUrl;
}
/**
* Gets calculated on.
*
* @return the calculated on
*/
public LocalDateTime getCalculatedOn() {
return calculatedOn;
}
/**
* Sets calculated on.
*
* @param calculatedOn the calculated on
*/
public void setCalculatedOn(LocalDateTime calculatedOn) {
this.calculatedOn = calculatedOn;
}
/**
* Gets temperature.
*
* @return the temperature
*/
public Temperature getTemperature() {
return temperature;
}
/**
* Sets temperature.
*
* @param temperature the temperature
*/
public void setTemperature(Temperature temperature) {
this.temperature = temperature;
}
/**
* Gets atmospheric pressure.
*
* @return the atmospheric pressure
*/
public AtmosphericPressure getAtmosphericPressure() {
return atmosphericPressure;
}
/**
* Sets atmospheric pressure.
*
* @param atmosphericPressure the atmospheric pressure
*/
public void setAtmosphericPressure(AtmosphericPressure atmosphericPressure) {
this.atmosphericPressure = atmosphericPressure;
}
/**
* Gets humidity.
*
* @return the humidity
*/
public Humidity getHumidity() {
return humidity;
}
/**
* Sets humidity.
*
* @param humidity the humidity
*/
public void setHumidity(Humidity humidity) {
this.humidity = humidity;
}
/**
* Gets wind.
*
* @return the wind
*/
public Wind getWind() {
return wind;
}
/**
* Sets wind.
*
* @param wind the wind
*/
public void setWind(Wind wind) {
this.wind = wind;
}
/**
* Gets rain.
*
* @return the rain
*/
public Rain getRain() {
return rain;
}
/**
* Sets rain.
*
* @param rain the rain
*/
public void setRain(Rain rain) {
this.rain = rain;
}
/**
* Gets snow.
*
* @return the snow
*/
public Snow getSnow() {
return snow;
}
/**
* Sets snow.
*
* @param snow the snow
*/
public void setSnow(Snow snow) {
this.snow = snow;
}
/**
* Gets clouds.
*
* @return the clouds
*/
public Clouds getClouds() {
return clouds;
}
/**
* Sets clouds.
*
* @param clouds the clouds
*/
public void setClouds(Clouds clouds) {
this.clouds = clouds;
}
/**
* Gets location.
*
* @return the location
*/
public Location getLocation() {
return location;
}
/**
* Sets location.
*
* @param location the location
*/
public void setLocation(Location location) {
this.location = location;
}

View File

@ -28,7 +28,6 @@ import java.util.Objects;
* The type Wind.
*/
public class Wind {
private double speed;
private Double degrees;
private Double gust;
@ -45,7 +44,13 @@ public class Wind {
this.unit = unit;
}
public static Wind forValue(double speed, String unit) {
/**
* Creates {@link Wind} object with correctness check.
* @param speed the speed
* @param unit the unitSystem
* @return wind object
*/
public static Wind withValue(double speed, String unit) {
if (speed < 0) {
throw new IllegalArgumentException("Wind speed value must be in positive or zero.");
}

View File

@ -24,5 +24,11 @@ package com.github.prominence.openweathermap.api.request;
import java.util.concurrent.CompletableFuture;
/**
* The interface Async request terminator.
*
* @param <T> the type parameter
* @param <S> the type parameter
*/
public interface AsyncRequestTerminator<T, S> extends RequestTerminator<CompletableFuture<T>, CompletableFuture<S>> {
}

View File

@ -25,9 +25,26 @@ package com.github.prominence.openweathermap.api.request;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
/**
* The interface Request customizer.
*
* @param <T> the type parameter
*/
public interface RequestCustomizer<T extends RequestCustomizer<?>> {
/**
* Customize language.
*
* @param language the language
* @return the request customizer
*/
T language(Language language);
/**
* Customize unit system.
*
* @param unitSystem the unit system
* @return the request customizer
*/
T unitSystem(UnitSystem unitSystem);
}

View File

@ -22,9 +22,25 @@
package com.github.prominence.openweathermap.api.request;
/**
* The interface Request terminator.
*
* @param <T> the type parameter
* @param <S> the type parameter
*/
public interface RequestTerminator<T, S> {
/**
* Java object response format.
*
* @return the java object
*/
T asJava();
/**
* JSON response format.
*
* @return the JSON string
*/
S asJSON();
}

View File

@ -29,6 +29,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/**
* The type Request url builder.
*/
public class RequestUrlBuilder {
private static final String API_KEY_PARAM_NAME = "appid";
@ -36,18 +39,40 @@ public class RequestUrlBuilder {
private final StringBuilder builder = new StringBuilder("http://api.openweathermap.org/data/2.5/");
private final Map<String, Object> requestParameters = new HashMap<>();
/**
* Instantiates a new Request url builder.
*
* @param key the API key
*/
public RequestUrlBuilder(String key) {
requestParameters.put(API_KEY_PARAM_NAME, key);
}
/**
* Appends value.
*
* @param value the value
*/
public void append(String value) {
builder.append(value);
}
/**
* Adds request parameter.
*
* @param key the key
* @param value the value
*/
public void addRequestParameter(String key, Object value) {
requestParameters.put(key, value);
}
/**
* Applies customization.
*
* @param language the language
* @param unitSystem the unit system
*/
public void applyCustomization(Language language, UnitSystem unitSystem) {
if (language != null) {
addRequestParameter("lang", language.getValue());
@ -57,6 +82,11 @@ public class RequestUrlBuilder {
}
}
/**
* Builds url string.
*
* @return the string
*/
public String buildUrl() {
final String joinedParameters = requestParameters.entrySet().stream()
.map(entry -> entry.getKey() + "=" + entry.getValue())

View File

@ -1,32 +0,0 @@
/*
* Copyright (c) 2021 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.request;
import java.util.List;
public interface ResponseMapper<T> {
T getSingle(String json);
List<T> getList(String json);
}

View File

@ -28,7 +28,15 @@ import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
import java.util.concurrent.CompletableFuture;
/**
* The forecast async request terminator interface.
*/
public interface FiveDayThreeHourStepForecastAsyncRequestTerminator extends AsyncRequestTerminator<Forecast, String> {
/**
* XML response format.
*
* @return the completable future
*/
CompletableFuture<String> asXML();
}

View File

@ -29,11 +29,20 @@ import com.github.prominence.openweathermap.api.utils.RequestUtils;
import java.util.concurrent.CompletableFuture;
/**
* Async request terminator.
*/
public class FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl implements FiveDayThreeHourStepForecastAsyncRequestTerminator {
private final RequestUrlBuilder urlBuilder;
private final UnitSystem unitSystem;
/**
* Instantiates a new async request terminator.
*
* @param urlBuilder the url builder
* @param unitSystem the unit system
*/
FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
this.urlBuilder = urlBuilder;
this.unitSystem = unitSystem;

View File

@ -24,11 +24,30 @@ package com.github.prominence.openweathermap.api.request.forecast.free;
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
/**
* The forecast request customizer interface.
*/
public interface FiveDayThreeHourStepForecastRequestCustomizer extends RequestCustomizer<FiveDayThreeHourStepForecastRequestCustomizer> {
/**
* Count customizer.
*
* @param numberOfTimestamps the number of timestamps
* @return forecast request customizer
*/
FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps);
/**
* Retrieve forecast request terminator.
*
* @return forecast request terminator
*/
FiveDayThreeHourStepForecastRequestTerminator retrieve();
/**
* Retrieve forecast async request terminator.
*
* @return forecast async request terminator
*/
FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync();
}

View File

@ -26,6 +26,9 @@ import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
/**
* The forecast request customizer.
*/
public class FiveDayThreeHourStepForecastRequestCustomizerImpl implements FiveDayThreeHourStepForecastRequestCustomizer {
private final RequestUrlBuilder urlBuilder;
@ -34,6 +37,11 @@ public class FiveDayThreeHourStepForecastRequestCustomizerImpl implements FiveDa
private UnitSystem unitSystem = UnitSystem.STANDARD;
private int count = -1;
/**
* Instantiates a new forecast request customizer.
*
* @param urlBuilder the url builder
*/
FiveDayThreeHourStepForecastRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
this.urlBuilder = urlBuilder;
}

View File

@ -26,7 +26,15 @@ import com.github.prominence.openweathermap.api.model.forecast.Forecast;
import com.github.prominence.openweathermap.api.request.RequestTerminator;
/**
* The forecast request terminator interface.
*/
public interface FiveDayThreeHourStepForecastRequestTerminator extends RequestTerminator<Forecast, String> {
/**
* XML response format.
*
* @return the XML string
*/
String asXML();
}

View File

@ -27,11 +27,20 @@ import com.github.prominence.openweathermap.api.model.forecast.Forecast;
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.utils.RequestUtils;
/**
* The forecast request terminator.
*/
public class FiveDayThreeHourStepForecastRequestTerminatorImpl implements FiveDayThreeHourStepForecastRequestTerminator {
private final RequestUrlBuilder urlBuilder;
private final UnitSystem unitSystem;
/**
* Instantiates a new forecast request terminator.
*
* @param urlBuilder the url builder
* @param unitSystem the unit system
*/
FiveDayThreeHourStepForecastRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
this.urlBuilder = urlBuilder;
this.unitSystem = unitSystem;

View File

@ -29,17 +29,63 @@ import com.github.prominence.openweathermap.api.model.Coordinate;
*/
public interface FiveDayThreeHourStepForecastRequester {
/**
* By city name forecast request customizer.
*
* @param cityName the city name
* @return the forecast request customizer
*/
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName);
/**
* By city name forecast request customizer.
*
* @param cityName the city name
* @param stateCode the state code
* @return the forecast request customizer
*/
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode);
/**
* By city name forecast request customizer.
*
* @param cityName the city name
* @param stateCode the state code
* @param countryCode the country code
* @return the forecast request customizer
*/
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode);
/**
* By city id forecast request customizer.
*
* @param cityId the city id
* @return the forecast request customizer
*/
FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId);
/**
* By coordinate forecast request customizer.
*
* @param coordinate the coordinate
* @return the forecast request customizer
*/
FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate);
/**
* By zip code and country forecast request customizer.
*
* @param zipCode the zip code
* @param countryCode the country code
* @return the forecast request customizer
*/
FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode);
/**
* By zip code in USA forecast request customizer.
*
* @param zipCode the zip code
* @return the forecast request customizer
*/
FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode);
}

View File

@ -25,10 +25,18 @@ package com.github.prominence.openweathermap.api.request.forecast.free;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
/**
* The forecast requester.
*/
public class FiveDayThreeHourStepForecastRequesterImpl implements FiveDayThreeHourStepForecastRequester {
private final RequestUrlBuilder urlBuilder;
/**
* Instantiates a new forecast requester.
*
* @param apiKey the api key
*/
public FiveDayThreeHourStepForecastRequesterImpl(String apiKey) {
urlBuilder = new RequestUrlBuilder(apiKey);
urlBuilder.append("forecast");

View File

@ -90,10 +90,21 @@ public class FiveDayThreeHourStepForecastResponseMapper {
private final UnitSystem unitSystem;
/**
* Instantiates a new forecast response mapper.
*
* @param unitSystem the unit system
*/
public FiveDayThreeHourStepForecastResponseMapper(UnitSystem unitSystem) {
this.unitSystem = unitSystem;
}
/**
* Maps forecast response into java object.
*
* @param json the json string
* @return the forecast
*/
public Forecast mapToForecast(String json) {
ObjectMapper objectMapper = new ObjectMapper();
Forecast forecast;
@ -151,7 +162,7 @@ public class FiveDayThreeHourStepForecastResponseMapper {
private Temperature parseTemperature(JsonNode rootNode) {
final double tempValue = rootNode.get("temp").asDouble();
Temperature temperature = Temperature.forValue(tempValue, unitSystem.getTemperatureUnit());
Temperature temperature = Temperature.withValue(tempValue, unitSystem.getTemperatureUnit());
final JsonNode tempMaxNode = rootNode.get("temp_max");
if (tempMaxNode != null) {
@ -170,7 +181,7 @@ public class FiveDayThreeHourStepForecastResponseMapper {
}
private AtmosphericPressure parsePressure(JsonNode rootNode) {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(rootNode.get("pressure").asDouble());
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(rootNode.get("pressure").asDouble());
final JsonNode seaLevelNode = rootNode.get("sea_level");
final JsonNode groundLevelNode = rootNode.get("grnd_level");
@ -185,14 +196,14 @@ public class FiveDayThreeHourStepForecastResponseMapper {
}
private Humidity parseHumidity(JsonNode rootNode) {
return Humidity.forValue((byte) (rootNode.get("humidity").asInt()));
return Humidity.withValue((byte) (rootNode.get("humidity").asInt()));
}
private Wind parseWind(JsonNode root) {
final JsonNode windNode = root.get("wind");
double speed = windNode.get("speed").asDouble();
Wind wind = Wind.forValue(speed, unitSystem.getWindUnit());
Wind wind = Wind.withValue(speed, unitSystem.getWindUnit());
final JsonNode degNode = windNode.get("deg");
if (degNode != null) {
wind.setDegrees(degNode.asDouble());
@ -202,34 +213,25 @@ public class FiveDayThreeHourStepForecastResponseMapper {
}
private Rain parseRain(JsonNode root) {
Rain rain = null;
final JsonNode rainNode = root.get("rain");
if (rainNode != null) {
rain = new Rain();
final JsonNode threeHourNode = rainNode.get("3h");
if (threeHourNode != null) {
rain.setThreeHourRainLevel(threeHourNode.asDouble());
return Rain.withThreeHourLevelValue(threeHourNode.asDouble());
}
}
return rain;
return null;
}
private Snow parseSnow(JsonNode root) {
Snow snow = null;
final JsonNode snowNode = root.get("snow");
if (snowNode != null) {
snow = new Snow();
final JsonNode threeHourNode = snowNode.get("3h");
if (threeHourNode != null) {
snow.setThreeHourSnowLevel(threeHourNode.asDouble());
Rain.withThreeHourLevelValue(threeHourNode.asDouble());
}
}
return snow;
return null;
}
private Clouds parseClouds(JsonNode rootNode) {
@ -238,14 +240,14 @@ public class FiveDayThreeHourStepForecastResponseMapper {
final JsonNode cloudsNode = rootNode.get("clouds");
final JsonNode allValueNode = cloudsNode.get("all");
if (allValueNode != null) {
clouds = Clouds.forValue((byte) allValueNode.asInt());
clouds = Clouds.withValue((byte) allValueNode.asInt());
}
return clouds;
}
private Location parseLocation(JsonNode rootNode) {
Location location = Location.forValue(rootNode.get("id").asInt(), rootNode.get("name").asText());
Location location = Location.withValues(rootNode.get("id").asInt(), rootNode.get("name").asText());
final JsonNode timezoneNode = rootNode.get("timezone");
if (timezoneNode != null) {
@ -283,7 +285,7 @@ public class FiveDayThreeHourStepForecastResponseMapper {
JsonNode latitudeNode = rootNode.get("lat");
JsonNode longitudeNode = rootNode.get("lon");
if (latitudeNode != null && longitudeNode != null) {
return Coordinate.forValues(latitudeNode.asDouble(), longitudeNode.asDouble());
return Coordinate.withValues(latitudeNode.asDouble(), longitudeNode.asDouble());
}
return null;
}

View File

@ -30,7 +30,17 @@ import com.github.prominence.openweathermap.api.request.weather.single.SingleLoc
*/
public interface CurrentWeatherRequester {
/**
* Single location current weather requester.
*
* @return the single location current weather requester
*/
SingleLocationCurrentWeatherRequester single();
/**
* Multiple locations current weather requester.
*
* @return the multiple locations current weather requester
*/
MultipleLocationsCurrentWeatherRequester multiple();
}

View File

@ -28,10 +28,18 @@ import com.github.prominence.openweathermap.api.request.weather.multiple.Multipl
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequesterImpl;
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequester;
/**
* The type Current weather requester.
*/
public class CurrentWeatherRequesterImpl implements CurrentWeatherRequester {
private final RequestUrlBuilder urlBuilder;
/**
* Instantiates a new Current weather requester.
*
* @param apiKey the api key
*/
public CurrentWeatherRequesterImpl(String apiKey) {
urlBuilder = new RequestUrlBuilder(apiKey);
}

View File

@ -25,7 +25,6 @@ package com.github.prominence.openweathermap.api.request.weather;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.prominence.openweathermap.api.model.weather.*;
import com.github.prominence.openweathermap.api.request.ResponseMapper;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.model.*;
@ -83,15 +82,25 @@ import java.util.TimeZone;
* --- name City name
* --- cod Internal parameter
*/
public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
public class CurrentWeatherResponseMapper {
private final UnitSystem unitSystem;
/**
* Instantiates a new Current weather response mapper.
*
* @param unitSystem the unit system
*/
public CurrentWeatherResponseMapper(UnitSystem unitSystem) {
this.unitSystem = unitSystem != null ? unitSystem : UnitSystem.STANDARD;
}
@Override
/**
* Gets single result.
*
* @param json the json string
* @return the weather object
*/
public Weather getSingle(String json) {
ObjectMapper objectMapper = new ObjectMapper();
Weather weather;
@ -127,7 +136,12 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
return weather;
}
@Override
/**
* Gets list of results.
*
* @param json the json string
* @return the list of weathers
*/
public List<Weather> getList(String json) {
ObjectMapper objectMapper = new ObjectMapper();
List<Weather> weatherList = new ArrayList<>();
@ -147,7 +161,7 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
final JsonNode mainNode = rootNode.get("main");
final double tempValue = mainNode.get("temp").asDouble();
temperature = Temperature.forValue(tempValue, unitSystem.getTemperatureUnit());
temperature = Temperature.withValue(tempValue, unitSystem.getTemperatureUnit());
final JsonNode feelsLikeNode = mainNode.get("feels_like");
if (feelsLikeNode != null) {
@ -167,7 +181,7 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
private AtmosphericPressure parsePressure(JsonNode rootNode) {
final JsonNode mainNode = rootNode.get("main");
AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(mainNode.get("pressure").asDouble());
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(mainNode.get("pressure").asDouble());
final JsonNode seaLevelNode = mainNode.get("sea_level");
final JsonNode groundLevelNode = mainNode.get("grnd_level");
@ -184,14 +198,14 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
private Humidity parseHumidity(JsonNode rootNode) {
final JsonNode mainNode = rootNode.get("main");
return Humidity.forValue((byte) (mainNode.get("humidity").asInt()));
return Humidity.withValue((byte) (mainNode.get("humidity").asInt()));
}
private Wind parseWind(JsonNode rootNode) {
final JsonNode windNode = rootNode.get("wind");
double speed = windNode.get("speed").asDouble();
Wind wind = Wind.forValue(speed, unitSystem.getWindUnit());
Wind wind = Wind.withValue(speed, unitSystem.getWindUnit());
final JsonNode degNode = windNode.get("deg");
if (degNode != null) {
@ -206,42 +220,35 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
}
private Rain parseRain(JsonNode rootNode) {
Rain rain = null;
final JsonNode rainNode = rootNode.get("rain");
if (rainNode != null) {
rain = new Rain();
final JsonNode oneHourNode = rainNode.get("1h");
final JsonNode threeHourNode = rainNode.get("3h");
if (oneHourNode != null) {
rain.setOneHourRainLevel(oneHourNode.asDouble());
}
if (threeHourNode != null) {
rain.setThreeHourRainLevel(threeHourNode.asDouble());
if (oneHourNode != null && oneHourNode.isDouble() && threeHourNode != null && threeHourNode.isDouble()) {
return Rain.withValues(oneHourNode.asDouble(), threeHourNode.asDouble());
} else if (oneHourNode != null && oneHourNode.isDouble()) {
return Rain.withOneHourLevelValue(oneHourNode.asDouble());
} else if (threeHourNode != null && threeHourNode.isDouble()) {
return Rain.withThreeHourLevelValue(threeHourNode.asDouble());
}
}
return rain;
return null;
}
private Snow parseSnow(JsonNode rootNode) {
Snow snow = null;
final JsonNode snowNode = rootNode.get("snow");
if (snowNode != null) {
snow = new Snow();
final JsonNode oneHourNode = snowNode.get("1h");
final JsonNode threeHourNode = snowNode.get("3h");
if (oneHourNode != null) {
snow.setOneHourSnowLevel(oneHourNode.asDouble());
}
if (threeHourNode != null) {
snow.setThreeHourSnowLevel(threeHourNode.asDouble());
if (oneHourNode != null && oneHourNode.isDouble() && threeHourNode != null && threeHourNode.isDouble()) {
return Snow.withValues(oneHourNode.asDouble(), threeHourNode.asDouble());
} else if (oneHourNode != null && oneHourNode.isDouble()) {
return Snow.withOneHourLevelValue(oneHourNode.asDouble());
} else if (threeHourNode != null && threeHourNode.isDouble()) {
return Snow.withThreeHourLevelValue(threeHourNode.asDouble());
}
}
return snow;
return null;
}
private Clouds parseClouds(JsonNode rootNode) {
@ -250,14 +257,14 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
final JsonNode cloudsNode = rootNode.get("clouds");
final JsonNode allValueNode = cloudsNode.get("all");
if (allValueNode != null) {
clouds = Clouds.forValue((byte) allValueNode.asInt());
clouds = Clouds.withValue((byte) allValueNode.asInt());
}
return clouds;
}
private Location parseLocation(JsonNode rootNode) {
Location location = Location.forValue(rootNode.get("id").asInt(), rootNode.get("name").asText());
Location location = Location.withValues(rootNode.get("id").asInt(), rootNode.get("name").asText());
final JsonNode timezoneNode = rootNode.get("timezone");
if (timezoneNode != null) {
@ -293,7 +300,7 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
JsonNode latitudeNode = rootNode.get("lat");
JsonNode longitudeNode = rootNode.get("lon");
if (latitudeNode != null && longitudeNode != null) {
return Coordinate.forValues(latitudeNode.asDouble(), longitudeNode.asDouble());
return Coordinate.withValues(latitudeNode.asDouble(), longitudeNode.asDouble());
}
return null;
}

View File

@ -25,12 +25,35 @@ package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
/**
* The interface Multiple locations current weather requester.
*/
public interface MultipleLocationsCurrentWeatherRequester {
/**
* By rectangle multiple result current weather request customizer.
*
* @param rectangle the rectangle
* @param zoom the zoom
* @return the multiple result current weather request customizer
*/
MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom);
/**
* By cities in cycle multiple result current weather request customizer.
*
* @param point the point
* @return the multiple result cities in circle current weather request customizer
*/
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point);
/**
* By cities in cycle multiple result current weather request customizer.
*
* @param point the point
* @param citiesCount the cities count
* @return the multiple result cities in circle current weather request customizer
*/
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount);
}

View File

@ -26,10 +26,18 @@ import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
/**
* The type Multiple locations current weather requester.
*/
public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLocationsCurrentWeatherRequester {
private final RequestUrlBuilder urlBuilder;
/**
* Instantiates a new Multiple locations current weather requester.
*
* @param urlBuilder the url builder
*/
public MultipleLocationsCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
this.urlBuilder = urlBuilder;
}

View File

@ -28,6 +28,14 @@ import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* The interface Multiple result current weather async request terminator.
*/
public interface MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<List<Weather>, String> {
/**
* XML response format.
*
* @return the completable future
*/
CompletableFuture<String> asXML();
}

View File

@ -31,11 +31,20 @@ import com.github.prominence.openweathermap.api.utils.RequestUtils;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* The type Multiple result current weather async request terminator.
*/
public class MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator {
private final RequestUrlBuilder urlBuilder;
private final UnitSystem unitSystem;
/**
* Instantiates a new Multiple result current weather async request terminator.
*
* @param urlBuilder the url builder
* @param unitSystem the unit system
*/
MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
this.urlBuilder = urlBuilder;
this.unitSystem = unitSystem;

View File

@ -24,9 +24,22 @@ package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
/**
* The interface Multiple result current weather request customizer.
*/
public interface MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer extends RequestCustomizer<MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer> {
/**
* Retrieve multiple result current weather request terminator.
*
* @return the multiple result current weather request terminator
*/
MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve();
/**
* Retrieve async multiple result current weather async request terminator.
*
* @return the multiple result current weather async request terminator
*/
MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync();
}

View File

@ -26,6 +26,9 @@ import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
/**
* The type Multiple result current weather request customizer.
*/
public class MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl implements MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer {
private final RequestUrlBuilder urlBuilder;
@ -33,6 +36,11 @@ public class MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl imp
private Language language;
private UnitSystem unitSystem = UnitSystem.STANDARD;
/**
* Instantiates a new Multiple result current weather request customizer.
*
* @param urlBuilder the url builder
*/
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
this.urlBuilder = urlBuilder;
}

View File

@ -27,6 +27,14 @@ import com.github.prominence.openweathermap.api.request.RequestTerminator;
import java.util.List;
/**
* The interface Multiple result current weather request terminator.
*/
public interface MultipleResultCitiesInCircleCurrentWeatherRequestTerminator extends RequestTerminator<List<Weather>, String> {
/**
* XML response format.
*
* @return the XML string
*/
String asXML();
}

View File

@ -30,11 +30,20 @@ import com.github.prominence.openweathermap.api.utils.RequestUtils;
import java.util.List;
/**
* The type Multiple result current weather request terminator.
*/
public class MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl implements MultipleResultCitiesInCircleCurrentWeatherRequestTerminator {
private final RequestUrlBuilder urlBuilder;
private final UnitSystem unitSystem;
/**
* Instantiates a new Multiple result current weather request terminator.
*
* @param urlBuilder the url builder
* @param unitSystem the unit system
*/
MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
this.urlBuilder = urlBuilder;
this.unitSystem = unitSystem;

View File

@ -27,5 +27,8 @@ import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
import java.util.List;
/**
* The interface Multiple result current weather async request terminator.
*/
public interface MultipleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<List<Weather>, String> {
}

View File

@ -31,11 +31,20 @@ import com.github.prominence.openweathermap.api.utils.RequestUtils;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* The type Multiple result current weather async request terminator.
*/
public class MultipleResultCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCurrentWeatherAsyncRequestTerminator {
private final RequestUrlBuilder urlBuilder;
private final UnitSystem unitSystem;
/**
* Instantiates a new Multiple result current weather async request terminator.
*
* @param urlBuilder the url builder
* @param unitSystem the unit system
*/
MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
this.urlBuilder = urlBuilder;
this.unitSystem = unitSystem;

View File

@ -24,9 +24,22 @@ package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
/**
* The interface Multiple result current weather request customizer.
*/
public interface MultipleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<MultipleResultCurrentWeatherRequestCustomizer> {
/**
* Retrieve multiple result current weather request terminator.
*
* @return the multiple result current weather request terminator
*/
MultipleResultCurrentWeatherRequestTerminator retrieve();
/**
* Retrieve async multiple result current weather async request terminator.
*
* @return the multiple result current weather async request terminator
*/
MultipleResultCurrentWeatherAsyncRequestTerminator retrieveAsync();
}

View File

@ -26,6 +26,9 @@ import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
/**
* The type Multiple result current weather request customizer.
*/
public class MultipleResultCurrentWeatherRequestCustomizerImpl implements MultipleResultCurrentWeatherRequestCustomizer {
private final RequestUrlBuilder urlBuilder;
@ -33,6 +36,11 @@ public class MultipleResultCurrentWeatherRequestCustomizerImpl implements Multip
private Language language;
private UnitSystem unitSystem = UnitSystem.STANDARD;
/**
* Instantiates a new Multiple result current weather request customizer.
*
* @param urlBuilder the url builder
*/
MultipleResultCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
this.urlBuilder = urlBuilder;
}

View File

@ -27,5 +27,8 @@ import com.github.prominence.openweathermap.api.request.RequestTerminator;
import java.util.List;
/**
* The interface Multiple result current weather request terminator.
*/
public interface MultipleResultCurrentWeatherRequestTerminator extends RequestTerminator<List<Weather>, String> {
}

View File

@ -30,11 +30,20 @@ import com.github.prominence.openweathermap.api.utils.RequestUtils;
import java.util.List;
/**
* The type Multiple result current weather request terminator.
*/
public class MultipleResultCurrentWeatherRequestTerminatorImpl implements MultipleResultCurrentWeatherRequestTerminator {
private final RequestUrlBuilder urlBuilder;
private final UnitSystem unitSystem;
/**
* Instantiates a new Multiple result current weather request terminator.
*
* @param urlBuilder the url builder
* @param unitSystem the unit system
*/
MultipleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
this.urlBuilder = urlBuilder;
this.unitSystem = unitSystem;

View File

@ -24,19 +24,68 @@ package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.model.Coordinate;
/**
* The interface Single location current weather requester.
*/
public interface SingleLocationCurrentWeatherRequester {
/**
* By city name current weather request customizer.
*
* @param cityName the city name
* @return the single result current weather request customizer
*/
SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName);
/**
* By city name current weather request customizer.
*
* @param cityName the city name
* @param countryCode the country code
* @return the single result current weather request customizer
*/
SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String countryCode);
/**
* By city name current weather request customizer.
*
* @param cityName the city name
* @param stateCode the state code
* @param countryCode the country code
* @return the single result current weather request customizer
*/
SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String stateCode, String countryCode);
/**
* By city id current weather request customizer.
*
* @param cityId the city id
* @return the single result current weather request customizer
*/
SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId);
/**
* By coordinate current weather request customizer.
*
* @param coordinate the coordinate
* @return the single result current weather request customizer
*/
SingleResultCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate);
/**
* By zip code and country current weather request customizer.
*
* @param zipCode the zip code
* @param countryCode the country code
* @return the single result current weather request customizer
*/
SingleResultCurrentWeatherRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode);
/**
* By zip code in usa current weather request customizer.
*
* @param zipCode the zip code
* @return the single result current weather request customizer
*/
SingleResultCurrentWeatherRequestCustomizer byZipCodeInUSA(String zipCode);
}

View File

@ -25,10 +25,18 @@ package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.model.Coordinate;
/**
* The type Single location current weather requester.
*/
public class SingleLocationCurrentWeatherRequesterImpl implements SingleLocationCurrentWeatherRequester {
private final RequestUrlBuilder urlBuilder;
/**
* Instantiates a new Single location current weather requester.
*
* @param urlBuilder the url builder
*/
public SingleLocationCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
this.urlBuilder = urlBuilder;
urlBuilder.append("weather");

View File

@ -27,8 +27,21 @@ import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
import java.util.concurrent.CompletableFuture;
/**
* The current weather async request terminator interface.
*/
public interface SingleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<Weather, String> {
/**
* XML response format.
*
* @return the completable future
*/
CompletableFuture<String> asXML();
/**
* HTML response format.
*
* @return the completable future
*/
CompletableFuture<String> asHTML();
}

View File

@ -30,11 +30,20 @@ import com.github.prominence.openweathermap.api.utils.RequestUtils;
import java.util.concurrent.CompletableFuture;
/**
* The type Single result current weather async request terminator.
*/
public class SingleResultCurrentWeatherAsyncRequestTerminatorImpl implements SingleResultCurrentWeatherAsyncRequestTerminator {
private final RequestUrlBuilder urlBuilder;
private final UnitSystem unitSystem;
/**
* Instantiates a new Single result current weather async request terminator.
*
* @param urlBuilder the url builder
* @param unitSystem the unit system
*/
SingleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
this.urlBuilder = urlBuilder;
this.unitSystem = unitSystem;

View File

@ -24,10 +24,23 @@ package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
/**
* The current weather request customizer interface.
*/
public interface SingleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<SingleResultCurrentWeatherRequestCustomizer> {
/**
* Retrieve current weather request terminator.
*
* @return the single result current weather request terminator
*/
SingleResultCurrentWeatherRequestTerminator retrieve();
/**
* Retrieve current weather async request terminator.
*
* @return the single result current weather async request terminator
*/
SingleResultCurrentWeatherAsyncRequestTerminator retrieveAsync();
}

View File

@ -26,6 +26,9 @@ import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
/**
* The type Single result current weather request customizer.
*/
public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleResultCurrentWeatherRequestCustomizer {
private final RequestUrlBuilder urlBuilder;
@ -33,6 +36,11 @@ public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleRe
private Language language;
private UnitSystem unitSystem = UnitSystem.STANDARD;
/**
* Instantiates a new Single result current weather request customizer.
*
* @param urlBuilder the url builder
*/
SingleResultCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
this.urlBuilder = urlBuilder;
}

View File

@ -25,8 +25,21 @@ package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.model.weather.Weather;
import com.github.prominence.openweathermap.api.request.RequestTerminator;
/**
* The current weather request terminator interface.
*/
public interface SingleResultCurrentWeatherRequestTerminator extends RequestTerminator<Weather, String> {
/**
* XML response format.
*
* @return the XML string
*/
String asXML();
/**
* HTML response format.
*
* @return the HTML string
*/
String asHTML();
}

View File

@ -28,11 +28,20 @@ import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.model.weather.Weather;
import com.github.prominence.openweathermap.api.utils.RequestUtils;
/**
* The type Single result current weather request terminator.
*/
public class SingleResultCurrentWeatherRequestTerminatorImpl implements SingleResultCurrentWeatherRequestTerminator {
private final RequestUrlBuilder urlBuilder;
private final UnitSystem unitSystem;
/**
* Instantiates a new Single result current weather request terminator.
*
* @param urlBuilder the url builder
* @param unitSystem the unit system
*/
SingleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
this.urlBuilder = urlBuilder;
this.unitSystem = unitSystem;

View File

@ -50,18 +50,18 @@ import org.junit.Test;
public class AtmosphericPressureUnitTest {
@Test
public void whenCreatePressureWithArgs_thenValueIsSet() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(100);
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(100);
Assert.assertEquals(100, atmosphericPressure.getValue(), 0.00001);
Assert.assertEquals(0, AtmosphericPressure.forValue(0).getValue(), 0.00001);
Assert.assertEquals(100, AtmosphericPressure.forValue(100).getValue(), 0.00001);
Assert.assertEquals(55, AtmosphericPressure.forValue(55).getValue(), 0.00001);
Assert.assertEquals(0, AtmosphericPressure.withValue(0).getValue(), 0.00001);
Assert.assertEquals(100, AtmosphericPressure.withValue(100).getValue(), 0.00001);
Assert.assertEquals(55, AtmosphericPressure.withValue(55).getValue(), 0.00001);
}
@Test
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
AtmosphericPressure one = AtmosphericPressure.forValue(22);
AtmosphericPressure two = AtmosphericPressure.forValue(22);
AtmosphericPressure one = AtmosphericPressure.withValue(22);
AtmosphericPressure two = AtmosphericPressure.withValue(22);
Assert.assertTrue(one.equals(two));
Assert.assertTrue(one.equals(one));
@ -80,17 +80,17 @@ public class AtmosphericPressureUnitTest {
@Test
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
AtmosphericPressure one = AtmosphericPressure.forValue(5);
AtmosphericPressure two = AtmosphericPressure.forValue(88);
AtmosphericPressure one = AtmosphericPressure.withValue(5);
AtmosphericPressure two = AtmosphericPressure.withValue(88);
Assert.assertFalse(one.equals(two));
Assert.assertFalse(two.equals(one));
Assert.assertFalse(one.equals(new Object()));
Assert.assertNotEquals(one.hashCode(), two.hashCode());
one = AtmosphericPressure.forValue(44);
one = AtmosphericPressure.withValue(44);
one.setSeaLevelValue(44);
two = AtmosphericPressure.forValue(44);
two = AtmosphericPressure.withValue(44);
two.setGroundLevelValue(22);
Assert.assertFalse(one.equals(two));
@ -104,7 +104,7 @@ public class AtmosphericPressureUnitTest {
@Test
public void whenSetValidValues_thenAllIsFine() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(14);
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(14);
atmosphericPressure.setValue(0);
atmosphericPressure.setValue(15);
atmosphericPressure.setValue(100);
@ -118,31 +118,31 @@ public class AtmosphericPressureUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final String pressureString = AtmosphericPressure.forValue(44).toString();
final String pressureString = AtmosphericPressure.withValue(44).toString();
Assert.assertNotNull(pressureString);
Assert.assertNotEquals("", pressureString);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreatePressureByConstructorWithInvalidDataNegative_thenThrowAnException() {
AtmosphericPressure.forValue(-33);
AtmosphericPressure.withValue(-33);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreatePressureAndSetInvalidDataNegative_thenThrowAnException() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(88);
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88);
atmosphericPressure.setValue(-89);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidSeaLevelPressure_thenThrowAnException() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(88);
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88);
atmosphericPressure.setSeaLevelValue(-89);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidGroundLevelPressure_thenThrowAnException() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(88);
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88);
atmosphericPressure.setGroundLevelValue(-223);
}
}

View File

@ -50,27 +50,27 @@ import org.junit.Test;
public class CloudsUnitTest {
@Test
public void whenCreateCloudsWithValidArgs_thenValueIsSet() {
Clouds clouds = Clouds.forValue((byte) 100);
Clouds clouds = Clouds.withValue((byte) 100);
Assert.assertEquals(100, clouds.getValue());
Assert.assertEquals(0, Clouds.forValue((byte) 0).getValue());
Assert.assertEquals(100, Clouds.forValue((byte) 100).getValue());
Assert.assertEquals(55, Clouds.forValue((byte) 55).getValue());
Assert.assertEquals(0, Clouds.withValue((byte) 0).getValue());
Assert.assertEquals(100, Clouds.withValue((byte) 100).getValue());
Assert.assertEquals(55, Clouds.withValue((byte) 55).getValue());
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCloudsByConstructorWithInvalidDataAboveHundred_thenThrowAnException() {
Clouds.forValue((byte) 110);
Clouds.withValue((byte) 110);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCloudsByConstructorWithInvalidDataNegative_thenThrowAnException() {
Clouds.forValue((byte) -33);
Clouds.withValue((byte) -33);
}
@Test
public void whenSetValidValues_thenAllIsFine() {
Clouds clouds = Clouds.forValue((byte) 14);
Clouds clouds = Clouds.withValue((byte) 14);
clouds.setValue((byte) 0);
Assert.assertEquals(0, clouds.getValue());
clouds.setValue((byte) 15);
@ -81,20 +81,20 @@ public class CloudsUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenCreateCloudsAndSetInvalidDataAboveHundred_thenThrowAnException() {
Clouds clouds = Clouds.forValue((byte) 12);
Clouds clouds = Clouds.withValue((byte) 12);
clouds.setValue((byte) 112);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCloudsAndSetInvalidDataNegative_thenThrowAnException() {
Clouds clouds = Clouds.forValue((byte) 88);
Clouds clouds = Clouds.withValue((byte) 88);
clouds.setValue((byte) -89);
}
@Test
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
Clouds one = Clouds.forValue((byte) 22);
Clouds two = Clouds.forValue((byte) 22);
Clouds one = Clouds.withValue((byte) 22);
Clouds two = Clouds.withValue((byte) 22);
Assert.assertTrue(one.equals(two));
Assert.assertTrue(one.equals(one));
@ -103,8 +103,8 @@ public class CloudsUnitTest {
@Test
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
Clouds one = Clouds.forValue((byte) 5);
Clouds two = Clouds.forValue((byte) 88);
Clouds one = Clouds.withValue((byte) 5);
Clouds two = Clouds.withValue((byte) 88);
Assert.assertFalse(one.equals(two));
Assert.assertFalse(two.equals(one));
@ -114,7 +114,7 @@ public class CloudsUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final String cloudsString = Clouds.forValue((byte) 44).toString();
final String cloudsString = Clouds.withValue((byte) 44).toString();
Assert.assertNotNull(cloudsString);
Assert.assertNotEquals("", cloudsString);
}

View File

@ -20,28 +20,6 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 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.model;
import org.junit.Assert;
@ -50,52 +28,93 @@ import org.junit.Test;
public class CoordinateRectangleUnitTest {
@Test
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLatitudeBottomBelowMinus90_thenThrowAnException() {
CoordinateRectangle.forValues(44.5, -91.2, 54.4, 22.2);
CoordinateRectangle.withValues(44.5, -91.2, 54.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLatitudeBottomAbove90_thenThrowAnException() {
CoordinateRectangle.forValues(44.5, 91.2, 54.4, 22.2);
CoordinateRectangle.withValues(44.5, 91.2, 54.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLatitudeTopBelowMinus90_thenThrowAnException() {
CoordinateRectangle.forValues(44.5, 22.4, 54.4, -92.3);
CoordinateRectangle.withValues(44.5, 22.4, 54.4, -92.3);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLatitudeTopAbove90_thenThrowAnException() {
CoordinateRectangle.forValues(44.5, 22.5, 54.4, 94.887);
CoordinateRectangle.withValues(44.5, 22.5, 54.4, 94.887);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLongitudeLeftBelowMinus180_thenThrowAnException() {
CoordinateRectangle.forValues(-944.5, 22.4, 54.4, 22.2);
CoordinateRectangle.withValues(-944.5, 22.4, 54.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLongitudeLeftAbove180_thenThrowAnException() {
CoordinateRectangle.forValues(544.5, 22.4, 54.4, 22.2);
CoordinateRectangle.withValues(544.5, 22.4, 54.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLongitudeRightBelowMinus180_thenThrowAnException() {
CoordinateRectangle.forValues(44.5, 22.4, -254.4, 22.2);
CoordinateRectangle.withValues(44.5, 22.4, -254.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLongitudeRightAbove180_thenThrowAnException() {
CoordinateRectangle.forValues(44.5, 22.4, 354.4, 22.2);
CoordinateRectangle.withValues(44.5, 22.4, 354.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectUsingBuilderWithInvalidLatitudeBottom_thenFail() {
new CoordinateRectangle.Builder()
.setLatitudeBottom(-1000);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectUsingBuilderWithInvalidLatitudeTop_thenFail() {
new CoordinateRectangle.Builder()
.setLatitudeTop(-1000);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectUsingBuilderWithInvalidLongitudeLeft_thenFail() {
new CoordinateRectangle.Builder()
.setLongitudeLeft(-1000);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectUsingBuilderWithInvalidLongitudeRight_thenFail() {
new CoordinateRectangle.Builder()
.setLongitudeRight(-1000);
}
@Test(expected = IllegalStateException.class)
public void whenCreateObjectUsingBuilderWithoutAllPropertiesSet_thenFail() {
new CoordinateRectangle.Builder()
.setLongitudeRight(10)
.build();
}
@Test
public void whenCreateObjectUsingBuilderWithCorrectUsage_thenOk() {
new CoordinateRectangle.Builder()
.setLongitudeRight(10)
.setLongitudeLeft(10)
.setLatitudeTop(10)
.setLatitudeBottom(10)
.build();
}
@Test
public void whenGetAllParameters_thenAllIsFine() {
final CoordinateRectangle rectangle = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
final CoordinateRectangle rectangle = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
Assert.assertEquals(44.5, rectangle.getLongitudeLeft(), 0.00001);
Assert.assertEquals(22.4, rectangle.getLatitudeBottom(), 0.00001);
Assert.assertEquals(54.4, rectangle.getLongitudeRight(), 0.00001);
@ -104,7 +123,7 @@ public class CoordinateRectangleUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final CoordinateRectangle rectangle = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
final CoordinateRectangle rectangle = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
Assert.assertNotNull(rectangle.toString());
Assert.assertNotEquals("", rectangle.toString());
@ -112,12 +131,12 @@ public class CoordinateRectangleUnitTest {
@Test
public void whenCallHashCode_thenAllIsFine() {
final CoordinateRectangle first = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
final CoordinateRectangle second = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
final CoordinateRectangle first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
final CoordinateRectangle second = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
Assert.assertEquals(first.hashCode(), second.hashCode());
final CoordinateRectangle third = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 23.566);
final CoordinateRectangle third = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 23.566);
Assert.assertNotEquals(first.hashCode(), third.hashCode());
Assert.assertNotEquals(second.hashCode(), third.hashCode());
@ -125,26 +144,26 @@ public class CoordinateRectangleUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
CoordinateRectangle first = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
CoordinateRectangle second = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
CoordinateRectangle first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
CoordinateRectangle second = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
Assert.assertFalse(first.equals(new Object()));
first = CoordinateRectangle.forValues(49.5, 22.4, 54.4, 22.2);
first = CoordinateRectangle.withValues(49.5, 22.4, 54.4, 22.2);
Assert.assertFalse(first.equals(second));
first = CoordinateRectangle.forValues(44.5, 29.4, 54.4, 22.2);
first = CoordinateRectangle.withValues(44.5, 29.4, 54.4, 22.2);
Assert.assertFalse(first.equals(second));
first = CoordinateRectangle.forValues(44.5, 22.4, 24.4, 22.2);
first = CoordinateRectangle.withValues(44.5, 22.4, 24.4, 22.2);
Assert.assertFalse(first.equals(second));
first = CoordinateRectangle.forValues(44.5, 22.4, 54.4, -2.2);
first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, -2.2);
Assert.assertFalse(first.equals(second));
}

View File

@ -20,28 +20,6 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 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.model;
import org.junit.Assert;
@ -50,32 +28,32 @@ import org.junit.Test;
public class CoordinateUnitTest {
@Test
public void whenCreateCoordinateWithValidValues_thenObjectCreated() {
Coordinate.forValues(44, 53);
Coordinate.withValues(44, 53);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCoordinateWithInvalidLatitudeBelowMinus90_thenThrowAnException() {
Coordinate.forValues(-333, 44);
Coordinate.withValues(-333, 44);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCoordinateWithInvalidLatitudeAbove90_thenThrowAnException() {
Coordinate.forValues(223, 44);
Coordinate.withValues(223, 44);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCoordinateWithInvalidLongitudeBelowMinus180_thenThrowAnException() {
Coordinate.forValues(33, -999);
Coordinate.withValues(33, -999);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCoordinateWithInvalidLongitudeAbove180_thenThrowAnException() {
Coordinate.forValues(33, 999);
Coordinate.withValues(33, 999);
}
@Test
public void whenSetValidCoordinates_thenAllIsFine() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLatitude(-90);
Assert.assertEquals(-90, coordinate.getLatitude(), 0.00001);
@ -94,31 +72,31 @@ public class CoordinateUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidLatitudeBelowMinus90_thenThrowAnException() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLatitude(-91);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidLatitudeAbove90_thenThrowAnException() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLatitude(92);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidLongitudeBelowMinus180_thenThrowAnException() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLongitude(-194);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidLongitudeAbove180_thenThrowAnException() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLongitude(444);
}
@Test
public void whenGetLatitude_thenAllIsFine() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
Assert.assertEquals(0, coordinate.getLatitude(), 0.00001);
coordinate.setLatitude(45);
@ -128,7 +106,7 @@ public class CoordinateUnitTest {
@Test
public void whenGetLongitude_thenAllIsFine() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
Assert.assertEquals(0, coordinate.getLongitude(), 0.00001);
coordinate.setLongitude(33);
@ -138,15 +116,15 @@ public class CoordinateUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
Assert.assertNotNull(coordinate.toString());
Assert.assertNotEquals("", coordinate.toString());
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final Coordinate first = Coordinate.forValues(22, 66);
final Coordinate second = Coordinate.forValues(22, 44);
final Coordinate first = Coordinate.withValues(22, 66);
final Coordinate second = Coordinate.withValues(22, 44);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
@ -165,8 +143,8 @@ public class CoordinateUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Coordinate first = Coordinate.forValues(11, 99);
final Coordinate second = Coordinate.forValues(11, 99);
final Coordinate first = Coordinate.withValues(11, 99);
final Coordinate second = Coordinate.withValues(11, 99);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));

View File

@ -20,28 +20,6 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 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.model;
import org.junit.Assert;
@ -50,26 +28,26 @@ import org.junit.Test;
public class HumidityUnitTest {
@Test
public void whenCreateHumidityWithArgs_thenValueIsSet() {
Humidity humidity = Humidity.forValue((byte) 100);
Humidity humidity = Humidity.withValue((byte) 100);
Assert.assertEquals(100, humidity.getValue());
Assert.assertEquals(0, Humidity.forValue((byte) 0).getValue());
Assert.assertEquals(55, Humidity.forValue((byte) 55).getValue());
Assert.assertEquals(0, Humidity.withValue((byte) 0).getValue());
Assert.assertEquals(55, Humidity.withValue((byte) 55).getValue());
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateHumidityByConstructorWithInvalidDataAboveHundred_thenThrowAnException() {
Humidity.forValue((byte) 112);
Humidity.withValue((byte) 112);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateHumidityByConstructorWithInvalidDataNegative_thenThrowAnException() {
Humidity.forValue((byte) -33);
Humidity.withValue((byte) -33);
}
@Test
public void whenSetValidValues_thenAllIsFine() {
Humidity humidity = Humidity.forValue((byte) 14);
Humidity humidity = Humidity.withValue((byte) 14);
Assert.assertEquals(14, humidity.getValue());
humidity.setValue((byte) 0);
Assert.assertEquals(0, humidity.getValue());
@ -81,20 +59,20 @@ public class HumidityUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenCreateHumidityAndSetInvalidDataAboveHundred_thenThrowAnException() {
Humidity humidity = Humidity.forValue((byte) 12);
Humidity humidity = Humidity.withValue((byte) 12);
humidity.setValue((byte) 112);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateHumidityAndSetInvalidDataNegative_thenThrowAnException() {
Humidity humidity = Humidity.forValue((byte) 88);
Humidity humidity = Humidity.withValue((byte) 88);
humidity.setValue((byte) -89);
}
@Test
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
Humidity one = Humidity.forValue((byte) 22);
Humidity two = Humidity.forValue((byte) 22);
Humidity one = Humidity.withValue((byte) 22);
Humidity two = Humidity.withValue((byte) 22);
Assert.assertTrue(one.equals(two));
Assert.assertTrue(one.equals(one));
@ -103,8 +81,8 @@ public class HumidityUnitTest {
@Test
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
Humidity one = Humidity.forValue((byte) 5);
Humidity two = Humidity.forValue((byte) 88);
Humidity one = Humidity.withValue((byte) 5);
Humidity two = Humidity.withValue((byte) 88);
Assert.assertFalse(one.equals(two));
Assert.assertFalse(two.equals(one));
@ -114,7 +92,7 @@ public class HumidityUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final String humidityString = Humidity.forValue((byte) 44).toString();
final String humidityString = Humidity.withValue((byte) 44).toString();
Assert.assertNotNull(humidityString);
Assert.assertNotEquals("", humidityString);
}

View File

@ -20,28 +20,6 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 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.model;
import org.junit.Assert;
@ -50,17 +28,17 @@ import org.junit.Test;
public class TemperatureUnitTest {
@Test
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
Temperature.forValue(22.2, "K");
Temperature.withValue(22.2, "K");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithEmptyUnit_thenThrowAnException() {
Temperature.forValue(22.2, null);
Temperature.withValue(22.2, null);
}
@Test
public void whenSetValue_thenAllIsFine() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setValue(55.44);
Assert.assertEquals(55.44, temperature.getValue(), 0.00001);
@ -68,7 +46,7 @@ public class TemperatureUnitTest {
@Test
public void whenSetMaximumTemperature_thenAllIsOk() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setMaxTemperature(44.4);
Assert.assertEquals(44.4, temperature.getMaxTemperature(), 0.00001);
@ -80,7 +58,7 @@ public class TemperatureUnitTest {
@Test
public void whenSetMinimumTemperature_thenAllIsOk() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setMinTemperature(33.2);
Assert.assertEquals(33.2, temperature.getMinTemperature(), 0.00001);
@ -92,7 +70,7 @@ public class TemperatureUnitTest {
@Test
public void whenSetFeelsLikeTemperature_thenAllIsOk() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setFeelsLike(22.3);
Assert.assertEquals(22.3, temperature.getFeelsLike(), 0.00001);
@ -104,7 +82,7 @@ public class TemperatureUnitTest {
@Test
public void whenSetNonNullUnit_thenAllIsOk() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setUnit("test");
Assert.assertTrue("test".equals(temperature.getUnit()));
@ -112,14 +90,14 @@ public class TemperatureUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetNullUnit_thenThrowAnException() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setUnit(null);
}
@Test
public void whenCallToString_thenAllIsFine() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
Assert.assertNotNull(temperature.toString());
Assert.assertNotEquals("", temperature.toString());
@ -142,16 +120,16 @@ public class TemperatureUnitTest {
@Test
public void whenCallHashCode_thenAllIsFine() {
final Temperature one = Temperature.forValue(22.2, "K");
final Temperature two = Temperature.forValue(22.2, "K");
final Temperature one = Temperature.withValue(22.2, "K");
final Temperature two = Temperature.withValue(22.2, "K");
Assert.assertEquals(one.hashCode(), two.hashCode());
}
@Test
public void whenCheckEquality_thenAllIsFine() {
final Temperature one = Temperature.forValue(22.2, "K");
final Temperature two = Temperature.forValue(21.2, "K");
final Temperature one = Temperature.withValue(22.2, "K");
final Temperature two = Temperature.withValue(21.2, "K");
Assert.assertTrue(one.equals(one));
Assert.assertFalse(one.equals(new Object()));

View File

@ -31,7 +31,7 @@ public class ForecastUnitTest {
@Test
public void whenLocationIsSet_thenAllIsOk() {
final Forecast forecast = new Forecast();
forecast.setLocation(Location.forValue(2, "asd"));
forecast.setLocation(Location.withValues(2, "asd"));
Assert.assertNotNull(forecast.getLocation());
}
@ -51,7 +51,7 @@ public class ForecastUnitTest {
Assert.assertEquals(one.hashCode(), two.hashCode());
one.setLocation(Location.forValue(22, "444"));
one.setLocation(Location.withValues(22, "444"));
Assert.assertNotEquals(one.hashCode(), two.hashCode());
}
@ -66,7 +66,7 @@ public class ForecastUnitTest {
Assert.assertTrue(one.equals(two));
Assert.assertFalse(one.equals(new Object()));
one.setLocation(Location.forValue(22, "234"));
one.setLocation(Location.withValues(22, "234"));
Assert.assertFalse(one.equals(two));

View File

@ -32,17 +32,17 @@ import java.time.ZoneOffset;
public class LocationUnitTest {
@Test
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
Location.forValue(33, "test");
Location.withValues(33, "test");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithoutName_thenThrowAnException() {
Location.forValue(33, null);
Location.withValues(33, null);
}
@Test
public void whenSetId_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setId(55);
Assert.assertEquals(55, location.getId());
@ -50,7 +50,7 @@ public class LocationUnitTest {
@Test
public void whenSetName_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setName("city");
Assert.assertEquals("city", location.getName());
@ -58,7 +58,7 @@ public class LocationUnitTest {
@Test
public void whenSetCountryCode_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setCountryCode("by");
Assert.assertEquals("by", location.getCountryCode());
@ -66,7 +66,7 @@ public class LocationUnitTest {
@Test
public void whenSetSunrise_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
final LocalDateTime now = LocalDateTime.now();
location.setSunrise(now);
@ -75,7 +75,7 @@ public class LocationUnitTest {
@Test
public void whenSetSunset_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
final LocalDateTime now = LocalDateTime.now();
location.setSunset(now);
@ -84,7 +84,7 @@ public class LocationUnitTest {
@Test
public void whenSetZoneOffset_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
final ZoneOffset offset = ZoneOffset.UTC;
location.setZoneOffset(offset);
@ -93,8 +93,8 @@ public class LocationUnitTest {
@Test
public void whenSetCoordinate_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Coordinate coordinate = Coordinate.forValues(33.2, 64.2);
final Location location = Location.withValues(33, "test");
final Coordinate coordinate = Coordinate.withValues(33.2, 64.2);
location.setCoordinate(coordinate);
Assert.assertEquals(coordinate, location.getCoordinate());
@ -102,7 +102,7 @@ public class LocationUnitTest {
@Test
public void whenSetPopulation_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setPopulation(3444L);
Assert.assertEquals(3444L, location.getPopulation().longValue());
@ -110,11 +110,11 @@ public class LocationUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final Location location = Location.forValue(44, "test");
final Location location = Location.withValues(44, "test");
Assert.assertNotEquals("", location.toString());
location.setCoordinate(Coordinate.forValues(33.2, 56.3));
location.setCoordinate(Coordinate.withValues(33.2, 56.3));
Assert.assertNotEquals("", location.toString());
@ -130,8 +130,8 @@ public class LocationUnitTest {
@Test
public void whenCallHashCode_thenAllIsFine() {
final Location one = Location.forValue(44, "test");
final Location two = Location.forValue(44, "test");
final Location one = Location.withValues(44, "test");
final Location two = Location.withValues(44, "test");
Assert.assertEquals(one.hashCode(), two.hashCode());
@ -142,8 +142,8 @@ public class LocationUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Location one = Location.forValue(44, "test");
final Location two = Location.forValue(44, "test");
final Location one = Location.withValues(44, "test");
final Location two = Location.withValues(44, "test");
Assert.assertTrue(one.equals(one));
Assert.assertFalse(one.equals(new Object()));
@ -200,7 +200,7 @@ public class LocationUnitTest {
Assert.assertTrue(one.equals(two));
final Coordinate coordinate = Coordinate.forValues(33.5, -22.4);
final Coordinate coordinate = Coordinate.withValues(33.5, -22.4);
one.setCoordinate(coordinate);

View File

@ -28,42 +28,44 @@ import org.junit.Test;
public class RainUnitTest {
@Test
public void whenCreateRainWithValidArgs_thenObjectIsCreated() {
new Rain(2222.3);
new Rain(null);
Rain.withThreeHourLevelValue(2222.3);
Rain.withThreeHourLevelValue(0);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateWithInvalidData_thenFail() {
Rain.withThreeHourLevelValue(-20);
}
@Test
public void whenSetValues_thenTheyAreSet() {
final Rain rain = new Rain(null);
final Rain rain = Rain.withThreeHourLevelValue(0);
Assert.assertNull(rain.getThreeHourRainLevel());
Assert.assertEquals(0, rain.getThreeHourRainLevel(), 0.00001);
rain.setThreeHourRainLevel(55.5);
Assert.assertEquals(55.5, rain.getThreeHourRainLevel(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidValue_thenFail() {
final Rain rain = Rain.withThreeHourLevelValue(0);
rain.setThreeHourRainLevel(-20);
}
@Test
public void whenCallToString_thenAllIsFine() {
final Rain rain = new Rain();
final Rain rain = Rain.withThreeHourLevelValue(33.5);
Assert.assertNotNull(rain.toString());
Assert.assertEquals("unknown", rain.toString());
rain.setThreeHourRainLevel(33.5);
Assert.assertNotNull(rain.toString());
Assert.assertNotEquals("unknown", rain.toString());
rain.setThreeHourRainLevel(null);
Assert.assertNotNull(rain.toString());
Assert.assertEquals("unknown", rain.toString());
Assert.assertNotEquals("", rain.toString());
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final Rain first = new Rain();
final Rain second = new Rain();
final Rain first = Rain.withThreeHourLevelValue(0);
final Rain second = Rain.withThreeHourLevelValue(0);
Assert.assertEquals(first.hashCode(), second.hashCode());
@ -78,8 +80,8 @@ public class RainUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Rain first = new Rain();
final Rain second = new Rain();
final Rain first = Rain.withThreeHourLevelValue(0);
final Rain second = Rain.withThreeHourLevelValue(0);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));

View File

@ -28,42 +28,43 @@ import org.junit.Test;
public class SnowUnitTest {
@Test
public void whenCreateSnowWithValidArgs_ObjectIsCreated() {
new Snow(2222.3);
new Snow(null);
Snow.withThreeHourLevelValue(2222.3);
Snow.withThreeHourLevelValue(0);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateWithInvalidData_thenFail() {
Snow.withThreeHourLevelValue(-20);
}
@Test
public void whenSetValues_thenTheyAreSet() {
final Snow snow = new Snow(null);
final Snow snow = Snow.withThreeHourLevelValue(0);
Assert.assertNull(snow.getThreeHourSnowLevel());
Assert.assertEquals(0, snow.getThreeHourSnowLevel(), 0.00001);
snow.setThreeHourSnowLevel(55.5);
Assert.assertEquals(55.5, snow.getThreeHourSnowLevel(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidValue_thenFail() {
final Snow snow = Snow.withThreeHourLevelValue(0);
snow.setThreeHourSnowLevel(-20);
}
@Test
public void whenCallToString_thenAllIsFine() {
final Snow snow = new Snow();
final Snow snow = Snow.withThreeHourLevelValue(33.5);
Assert.assertNotNull(snow.toString());
Assert.assertEquals("unknown", snow.toString());
snow.setThreeHourSnowLevel(33.5);
Assert.assertNotNull(snow.toString());
Assert.assertNotEquals("unknown", snow.toString());
snow.setThreeHourSnowLevel(null);
Assert.assertNotNull(snow.toString());
Assert.assertEquals("unknown", snow.toString());
Assert.assertNotEquals("", snow.toString());
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final Snow first = new Snow();
final Snow second = new Snow();
final Snow first = Snow.withThreeHourLevelValue(0);
final Snow second = Snow.withThreeHourLevelValue(0);
Assert.assertEquals(first.hashCode(), second.hashCode());
@ -78,8 +79,8 @@ public class SnowUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Snow first = new Snow();
final Snow second = new Snow();
final Snow first = Snow.withThreeHourLevelValue(0);
final Snow second = Snow.withThreeHourLevelValue(0);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));

View File

@ -20,28 +20,6 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 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.model.forecast;
import com.github.prominence.openweathermap.api.model.*;
@ -114,7 +92,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetTemperature_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Temperature temperature = Temperature.forValue(22.3, "a");
final Temperature temperature = Temperature.withValue(22.3, "a");
weatherForecast.setTemperature(temperature);
Assert.assertEquals(temperature, weatherForecast.getTemperature());
@ -123,7 +101,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetPressure_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(33.2);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.2);
weatherForecast.setAtmosphericPressure(atmosphericPressure);
Assert.assertEquals(atmosphericPressure, weatherForecast.getAtmosphericPressure());
@ -132,7 +110,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetHumidity_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Humidity humidity = Humidity.forValue((byte) 44);
final Humidity humidity = Humidity.withValue((byte) 44);
weatherForecast.setHumidity(humidity);
Assert.assertEquals(humidity, weatherForecast.getHumidity());
@ -141,7 +119,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetWind_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Wind wind = Wind.forValue(22.2, "a");
final Wind wind = Wind.withValue(22.2, "a");
weatherForecast.setWind(wind);
Assert.assertEquals(wind, weatherForecast.getWind());
@ -150,7 +128,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetRain_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Rain rain = new Rain();
final Rain rain = Rain.withThreeHourLevelValue(0);
weatherForecast.setRain(rain);
Assert.assertEquals(rain, weatherForecast.getRain());
@ -159,7 +137,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetSnow_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Snow snow = new Snow();
final Snow snow = Snow.withThreeHourLevelValue(0);
weatherForecast.setSnow(snow);
Assert.assertEquals(snow, weatherForecast.getSnow());
@ -168,7 +146,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetClouds_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Clouds clouds = Clouds.forValue((byte) 33);
final Clouds clouds = Clouds.withValue((byte) 33);
weatherForecast.setClouds(clouds);
Assert.assertEquals(clouds, weatherForecast.getClouds());
@ -199,12 +177,12 @@ public class WeatherForecastUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Location location = Location.forValue(12312, "asd");
final Temperature temperature = Temperature.forValue(33.2, "asd");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(44.4);
final Clouds clouds = Clouds.forValue((byte) 55);
final Rain rain = new Rain(33.2);
final Snow snow = new Snow(33.1);
final Location location = Location.withValues(12312, "asd");
final Temperature temperature = Temperature.withValue(33.2, "asd");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(44.4);
final Clouds clouds = Clouds.withValue((byte) 55);
final Rain rain = Rain.withThreeHourLevelValue(33.2);
final Snow snow = Snow.withThreeHourLevelValue(33.1);
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
@ -241,11 +219,11 @@ public class WeatherForecastUnitTest {
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
weatherForecast.setRain(new Rain(null));
weatherForecast.setRain(Rain.withThreeHourLevelValue(0));
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
weatherForecast.setSnow(new Snow(null));
weatherForecast.setSnow(Snow.withThreeHourLevelValue(0));
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
}
@ -297,7 +275,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final Temperature temperature = Temperature.forValue(33.2, "as");
final Temperature temperature = Temperature.withValue(33.2, "as");
one.setTemperature(temperature);
Assert.assertFalse(one.equals(two));
@ -306,7 +284,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(33.33);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.33);
one.setAtmosphericPressure(atmosphericPressure);
Assert.assertFalse(one.equals(two));
@ -315,7 +293,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final Humidity humidity = Humidity.forValue((byte) 33);
final Humidity humidity = Humidity.withValue((byte) 33);
one.setHumidity(humidity);
Assert.assertFalse(one.equals(two));
@ -324,7 +302,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final Wind wind = Wind.forValue(33.6, "asd");
final Wind wind = Wind.withValue(33.6, "asd");
one.setWind(wind);
Assert.assertFalse(one.equals(two));
@ -333,7 +311,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final Rain rain = new Rain();
final Rain rain = Rain.withThreeHourLevelValue(0);
one.setRain(rain);
Assert.assertFalse(one.equals(two));
@ -342,7 +320,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final Snow snow = new Snow();
final Snow snow = Snow.withThreeHourLevelValue(0);
one.setSnow(snow);
Assert.assertFalse(one.equals(two));
@ -351,7 +329,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final Clouds clouds = Clouds.forValue((byte) 33);
final Clouds clouds = Clouds.withValue((byte) 33);
one.setClouds(clouds);
Assert.assertFalse(one.equals(two));

View File

@ -28,22 +28,22 @@ import org.junit.Test;
public class WindUnitTest {
@Test
public void whenCreateWindWithValidArgs_thenValueIsSet() {
Assert.assertEquals(44.0, Wind.forValue(44, "ms").getSpeed(), 0.00001);
Assert.assertEquals(44.0, Wind.withValue(44, "ms").getSpeed(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateWindWithInvalidSpeedArg_thenThrowAnException() {
Wind.forValue(-21, "a");
Wind.withValue(-21, "a");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateWindWithInvalidUnitArg_thenThrowAnException() {
Wind.forValue(342, null);
Wind.withValue(342, null);
}
@Test
public void whenSetValidSpeed_thenValueIsSet() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
@ -58,7 +58,7 @@ public class WindUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidSpeedBelow0_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
@ -67,7 +67,7 @@ public class WindUnitTest {
@Test
public void whenSetValidDegrees_thenValueIsSet() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertNull(wind.getDegrees());
@ -86,19 +86,19 @@ public class WindUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidDegreesBelow0_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setDegrees(-32);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidDegreesAbove360_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setDegrees(378);
}
@Test
public void whenSetNonNullUnit_thenValueIsSet() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(wind.getUnit(), "as");
@ -109,14 +109,14 @@ public class WindUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetNullUnit_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setUnit(null);
}
@Test
public void whenCallToString_thenAllIsFine() {
final Wind wind = Wind.forValue(302, "a");
final Wind wind = Wind.withValue(302, "a");
Assert.assertNotNull(wind.toString());
@ -128,8 +128,8 @@ public class WindUnitTest {
@Test
public void whenCallHashCode_thenAllIsFine() {
final Wind first = Wind.forValue(22, "a");
final Wind second = Wind.forValue(22, "b");
final Wind first = Wind.withValue(22, "a");
final Wind second = Wind.withValue(22, "b");
Assert.assertNotEquals(first.hashCode(), second.hashCode());
@ -152,8 +152,8 @@ public class WindUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Wind first = Wind.forValue(11, "a");
final Wind second = Wind.forValue(11, "a");
final Wind first = Wind.withValue(11, "a");
final Wind second = Wind.withValue(11, "a");
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));

View File

@ -32,17 +32,17 @@ import java.time.ZoneOffset;
public class LocationUnitTest {
@Test
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
Location.forValue(33, "test");
Location.withValues(33, "test");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithoutName_thenThrowAnException() {
Location.forValue(33, null);
Location.withValues(33, null);
}
@Test
public void whenSetId_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setId(55);
Assert.assertEquals(55, location.getId());
@ -50,7 +50,7 @@ public class LocationUnitTest {
@Test
public void whenSetName_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setName("city");
Assert.assertEquals("city", location.getName());
@ -58,7 +58,7 @@ public class LocationUnitTest {
@Test
public void whenSetCountryCode_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setCountryCode("by");
Assert.assertEquals("by", location.getCountryCode());
@ -66,7 +66,7 @@ public class LocationUnitTest {
@Test
public void whenSetSunrise_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
final LocalDateTime now = LocalDateTime.now();
location.setSunrise(now);
@ -75,7 +75,7 @@ public class LocationUnitTest {
@Test
public void whenSetSunset_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
final LocalDateTime now = LocalDateTime.now();
location.setSunset(now);
@ -84,7 +84,7 @@ public class LocationUnitTest {
@Test
public void whenSetZoneOffset_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
final ZoneOffset offset = ZoneOffset.UTC;
location.setZoneOffset(offset);
@ -93,8 +93,8 @@ public class LocationUnitTest {
@Test
public void whenSetCoordinate_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Coordinate coordinate = Coordinate.forValues(33.2, 64.2);
final Location location = Location.withValues(33, "test");
final Coordinate coordinate = Coordinate.withValues(33.2, 64.2);
location.setCoordinate(coordinate);
Assert.assertEquals(coordinate, location.getCoordinate());
@ -102,11 +102,11 @@ public class LocationUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final Location location = Location.forValue(44, "test");
final Location location = Location.withValues(44, "test");
Assert.assertNotEquals("", location.toString());
location.setCoordinate(Coordinate.forValues(33.2, 56.3));
location.setCoordinate(Coordinate.withValues(33.2, 56.3));
Assert.assertNotEquals("", location.toString());
@ -118,8 +118,8 @@ public class LocationUnitTest {
@Test
public void whenCallHashCode_thenAllIsFine() {
final Location one = Location.forValue(44, "test");
final Location two = Location.forValue(44, "test");
final Location one = Location.withValues(44, "test");
final Location two = Location.withValues(44, "test");
Assert.assertEquals(one.hashCode(), two.hashCode());
@ -130,8 +130,8 @@ public class LocationUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Location one = Location.forValue(44, "test");
final Location two = Location.forValue(44, "test");
final Location one = Location.withValues(44, "test");
final Location two = Location.withValues(44, "test");
Assert.assertTrue(one.equals(one));
Assert.assertFalse(one.equals(new Object()));
@ -188,7 +188,7 @@ public class LocationUnitTest {
Assert.assertTrue(one.equals(two));
final Coordinate coordinate = Coordinate.forValues(33.5, -22.4);
final Coordinate coordinate = Coordinate.withValues(33.5, -22.4);
one.setCoordinate(coordinate);

View File

@ -28,18 +28,14 @@ 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);
Rain.withValues(2222.3, 324234.3);
Rain.withThreeHourLevelValue(213123.4);
Rain.withOneHourLevelValue(123123.123);
}
@Test
public void whenSetValues_thenTheyAreSet() {
final Rain rain = new Rain(null, null);
Assert.assertNull(rain.getOneHourRainLevel());
Assert.assertNull(rain.getThreeHourRainLevel());
final Rain rain = Rain.withValues(0, 0);
rain.setOneHourRainLevel(33.3);
Assert.assertEquals(33.3, rain.getOneHourRainLevel(), 0.00001);
@ -50,31 +46,33 @@ public class RainUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final Rain rain = new Rain();
Rain rain = Rain.withThreeHourLevelValue(33.5);
Assert.assertNotNull(rain.toString());
Assert.assertEquals("unknown", rain.toString());
rain.setThreeHourRainLevel(33.5);
Assert.assertNotNull(rain.toString());
Assert.assertNotEquals("unknown", rain.toString());
Assert.assertNotEquals("", rain.toString());
rain.setOneHourRainLevel(22.2);
Assert.assertNotNull(rain.toString());
Assert.assertNotEquals("unknown", rain.toString());
Assert.assertNotEquals("", rain.toString());
}
rain.setThreeHourRainLevel(null);
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidOneHourLevelValue_thenFail() {
final Rain rain = Rain.withValues(0, 0);
rain.setOneHourRainLevel(-20);
}
Assert.assertNotNull(rain.toString());
Assert.assertNotEquals("unknown", rain.toString());
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidThreeHourLevelValue_thenFail() {
final Rain rain = Rain.withValues(0, 0);
rain.setThreeHourRainLevel(-20);
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final Rain first = new Rain();
final Rain second = new Rain();
final Rain first = Rain.withValues(0, 0);
final Rain second = Rain.withValues(0, 0);
Assert.assertEquals(first.hashCode(), second.hashCode());
@ -97,8 +95,8 @@ public class RainUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Rain first = new Rain();
final Rain second = new Rain();
final Rain first = Rain.withValues(0, 0);
final Rain second = Rain.withValues(0, 0);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));

View File

@ -28,18 +28,14 @@ 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);
Snow.withValues(2222.3, 324234.3);
Snow.withThreeHourLevelValue(213123.4);
Snow.withOneHourLevelValue(123123.123);
}
@Test
public void whenSetValues_thenTheyAreSet() {
final Snow snow = new Snow(null, null);
Assert.assertNull(snow.getOneHourSnowLevel());
Assert.assertNull(snow.getThreeHourSnowLevel());
final Snow snow = Snow.withValues(0, 0);
snow.setOneHourSnowLevel(33.3);
Assert.assertEquals(33.3, snow.getOneHourSnowLevel(), 0.00001);
@ -48,33 +44,40 @@ public class SnowUnitTest {
Assert.assertEquals(55.5, snow.getThreeHourSnowLevel(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidOneHourLevelValue_thenFail() {
final Snow rain = Snow.withValues(0, 0);
rain.setOneHourSnowLevel(-20);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidThreeHourLevelValue_thenFail() {
final Snow rain = Snow.withValues(0, 0);
rain.setThreeHourSnowLevel(-20);
}
@Test
public void whenCallToString_thenAllIsFine() {
final Snow snow = new Snow();
final Snow snow = Snow.withOneHourLevelValue(33.5);
Assert.assertNotNull(snow.toString());
Assert.assertEquals("unknown", snow.toString());
snow.setThreeHourSnowLevel(33.5);
Assert.assertNotNull(snow.toString());
Assert.assertNotEquals("unknown", snow.toString());
Assert.assertNotEquals("", snow.toString());
snow.setOneHourSnowLevel(22.2);
Assert.assertNotNull(snow.toString());
Assert.assertNotEquals("unknown", snow.toString());
Assert.assertNotEquals("", snow.toString());
snow.setThreeHourSnowLevel(null);
snow.setThreeHourSnowLevel(33.2);
Assert.assertNotNull(snow.toString());
Assert.assertNotEquals("unknown", snow.toString());
Assert.assertNotEquals("", snow.toString());
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final Snow first = new Snow();
final Snow second = new Snow();
final Snow first = Snow.withValues(0, 0);
final Snow second = Snow.withValues(0, 0);
Assert.assertEquals(first.hashCode(), second.hashCode());
@ -97,8 +100,8 @@ public class SnowUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Snow first = new Snow();
final Snow second = new Snow();
final Snow first = Snow.withValues(0, 0);
final Snow second = Snow.withValues(0, 0);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));

View File

@ -95,7 +95,7 @@ public class WeatherUnitTest {
@Test
public void whenSetTemperature_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Temperature temperature = Temperature.forValue(22.3, "a");
final Temperature temperature = Temperature.withValue(22.3, "a");
weather.setTemperature(temperature);
Assert.assertEquals(temperature, weather.getTemperature());
@ -104,7 +104,7 @@ public class WeatherUnitTest {
@Test
public void whenSetPressure_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(33.2);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.2);
weather.setAtmosphericPressure(atmosphericPressure);
Assert.assertEquals(atmosphericPressure, weather.getAtmosphericPressure());
@ -113,7 +113,7 @@ public class WeatherUnitTest {
@Test
public void whenSetHumidity_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Humidity humidity = Humidity.forValue((byte) 44);
final Humidity humidity = Humidity.withValue((byte) 44);
weather.setHumidity(humidity);
Assert.assertEquals(humidity, weather.getHumidity());
@ -122,7 +122,7 @@ public class WeatherUnitTest {
@Test
public void whenSetWind_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Wind wind = Wind.forValue(22.2, "a");
final Wind wind = Wind.withValue(22.2, "a");
weather.setWind(wind);
Assert.assertEquals(wind, weather.getWind());
@ -131,7 +131,7 @@ public class WeatherUnitTest {
@Test
public void whenSetRain_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Rain rain = new Rain();
final Rain rain = Rain.withValues(0, 0);
weather.setRain(rain);
Assert.assertEquals(rain, weather.getRain());
@ -140,7 +140,7 @@ public class WeatherUnitTest {
@Test
public void whenSetSnow_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Snow snow = new Snow();
final Snow snow = Snow.withValues(0, 0);
weather.setSnow(snow);
Assert.assertEquals(snow, weather.getSnow());
@ -149,7 +149,7 @@ public class WeatherUnitTest {
@Test
public void whenSetClouds_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Clouds clouds = Clouds.forValue((byte) 33);
final Clouds clouds = Clouds.withValue((byte) 33);
weather.setClouds(clouds);
Assert.assertEquals(clouds, weather.getClouds());
@ -158,7 +158,7 @@ public class WeatherUnitTest {
@Test
public void whenSetLocation_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Location location = Location.forValue(22, "asd");
final Location location = Location.withValues(22, "asd");
weather.setLocation(location);
Assert.assertEquals(location, weather.getLocation());
@ -167,12 +167,12 @@ public class WeatherUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final Weather weather = Weather.forValue("state", "desc");
final Location location = Location.forValue(12312, "asd");
final Temperature temperature = Temperature.forValue(33.2, "asd");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(44.4);
final Clouds clouds = Clouds.forValue((byte) 55);
final Rain rain = new Rain(33.2, null);
final Snow snow = new Snow(33.1, null);
final Location location = Location.withValues(12312, "asd");
final Temperature temperature = Temperature.withValue(33.2, "asd");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(44.4);
final Clouds clouds = Clouds.withValue((byte) 55);
final Rain rain = Rain.withOneHourLevelValue(33.2);
final Snow snow = Snow.withOneHourLevelValue(33.1);
Assert.assertNotEquals("", weather.toString());
Assert.assertNotNull(weather.toString());
@ -252,7 +252,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Temperature temperature = Temperature.forValue(33.2, "as");
final Temperature temperature = Temperature.withValue(33.2, "as");
one.setTemperature(temperature);
Assert.assertFalse(one.equals(two));
@ -261,7 +261,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(33.33);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.33);
one.setAtmosphericPressure(atmosphericPressure);
Assert.assertFalse(one.equals(two));
@ -270,7 +270,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Humidity humidity = Humidity.forValue((byte) 33);
final Humidity humidity = Humidity.withValue((byte) 33);
one.setHumidity(humidity);
Assert.assertFalse(one.equals(two));
@ -279,7 +279,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Wind wind = Wind.forValue(33.6, "asd");
final Wind wind = Wind.withValue(33.6, "asd");
one.setWind(wind);
Assert.assertFalse(one.equals(two));
@ -288,7 +288,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Rain rain = new Rain();
final Rain rain = Rain.withValues(0, 0);
one.setRain(rain);
Assert.assertFalse(one.equals(two));
@ -297,7 +297,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Snow snow = new Snow();
final Snow snow = Snow.withValues(0, 0);
one.setSnow(snow);
Assert.assertFalse(one.equals(two));
@ -306,7 +306,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Clouds clouds = Clouds.forValue((byte) 33);
final Clouds clouds = Clouds.withValue((byte) 33);
one.setClouds(clouds);
Assert.assertFalse(one.equals(two));
@ -315,7 +315,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Location location = Location.forValue(231, "asda");
final Location location = Location.withValues(231, "asda");
one.setLocation(location);
Assert.assertFalse(one.equals(two));

View File

@ -28,22 +28,22 @@ import org.junit.Test;
public class WindUnitTest {
@Test
public void whenCreateWindWithValidArgs_thenValueIsSet() {
Assert.assertEquals(44.0, Wind.forValue(44, "ms").getSpeed(), 0.00001);
Assert.assertEquals(44.0, Wind.withValue(44, "ms").getSpeed(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateWindWithInvalidSpeedArg_thenThrowAnException() {
Wind.forValue(-21, "a");
Wind.withValue(-21, "a");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateWindWithInvalidUnitArg_thenThrowAnException() {
Wind.forValue(342, null);
Wind.withValue(342, null);
}
@Test
public void whenSetValidSpeed_thenValueIsSet() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
@ -58,7 +58,7 @@ public class WindUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidSpeedBelow0_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
@ -67,7 +67,7 @@ public class WindUnitTest {
@Test
public void whenSetValidDegrees_thenValueIsSet() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertNull(wind.getDegrees());
@ -86,19 +86,19 @@ public class WindUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidDegreesBelow0_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setDegrees(-32);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidDegreesAbove360_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setDegrees(378);
}
@Test
public void whenSetNonNullUnit_thenValueIsSet() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(wind.getUnit(), "as");
@ -109,21 +109,21 @@ public class WindUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetNullUnit_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setUnit(null);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidGustValue_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setGust(-50);
}
@Test
public void whenSetValidGustValue_thenAllIsFine() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setGust(30);
@ -132,7 +132,7 @@ public class WindUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final Wind wind = Wind.forValue(302, "a");
final Wind wind = Wind.withValue(302, "a");
Assert.assertNotNull(wind.toString());
@ -148,8 +148,8 @@ public class WindUnitTest {
@Test
public void whenCallHashCode_thenAllIsFine() {
final Wind first = Wind.forValue(22, "a");
final Wind second = Wind.forValue(22, "b");
final Wind first = Wind.withValue(22, "a");
final Wind second = Wind.withValue(22, "b");
Assert.assertNotEquals(first.hashCode(), second.hashCode());
@ -172,8 +172,8 @@ public class WindUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Wind first = Wind.forValue(11, "a");
final Wind second = Wind.forValue(11, "a");
final Wind first = Wind.withValue(11, "a");
final Wind second = Wind.withValue(11, "a");
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));

View File

@ -252,7 +252,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
public void whenGetForecastByCoordinatesRequestAsJava_thenReturnNotNull() {
final Forecast forecast = getClient()
.forecast5Day3HourStep()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.count(15)
@ -277,7 +277,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
public void whenGetForecastByCoordinatesRequestAsJSON_thenReturnNotNull() {
final String forecastJson = getClient()
.forecast5Day3HourStep()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.language(Language.SPANISH)
.unitSystem(UnitSystem.IMPERIAL)
.count(15)
@ -291,7 +291,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
public void whenGetForecastByCoordinatesRequestAsXML_thenReturnNotNull() {
final String forecastXml = getClient()
.forecast5Day3HourStep()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()

View File

@ -44,7 +44,15 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byRectangle(CoordinateRectangle.forValues(12, 32, 15, 37), 10)
.byRectangle(
new CoordinateRectangle.Builder()
.setLongitudeLeft(12)
.setLatitudeBottom(32)
.setLongitudeRight(15)
.setLatitudeTop(37)
.build(),
10
)
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@ -69,7 +77,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherJson = getClient()
.currentWeather()
.multiple()
.byRectangle(CoordinateRectangle.forValues(12, 32, 15, 37), 10)
.byRectangle(CoordinateRectangle.withValues(12, 32, 15, 37), 10)
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@ -83,7 +91,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5))
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
@ -109,7 +117,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherJson = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5))
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
@ -123,7 +131,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherXml = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5))
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
@ -138,7 +146,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
@ -164,7 +172,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherJson = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
@ -178,7 +186,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherXml = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
@ -192,7 +200,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final CompletableFuture<List<Weather>> weatherListFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
@ -209,7 +217,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()

View File

@ -298,7 +298,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
final Weather weather = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
@ -320,7 +320,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherJson = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJSON();
@ -333,7 +333,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherXml = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asXML();
@ -346,7 +346,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherHtml = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asHTML();
@ -550,7 +550,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
client
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(34.53, 66.74), 10)
.byCitiesInCycle(Coordinate.withValues(34.53, 66.74), 10)
.retrieve()
.asJSON();
}
@ -560,7 +560,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(90.00, 66.74), 10)
.byCitiesInCycle(Coordinate.withValues(90.00, 66.74), 10)
.retrieve()
.asJava();
}

View File

@ -1,3 +1,25 @@
/*
* Copyright (c) 2021 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.utils;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;