2.1.0 version implementation.

This commit is contained in:
Alexey Zinchenko
2021-04-12 02:00:51 +03:00
committed by GitHub
parent 196f9ec289
commit 4cfa8ab843
126 changed files with 11406 additions and 1705 deletions
@@ -22,19 +22,18 @@
package com.github.prominence.openweathermap.api;
import org.junit.BeforeClass;
import org.junit.jupiter.api.BeforeAll;
public class ApiTest {
private static OpenWeatherMapClient client;
private static OpenWeatherMapClient manager;
@BeforeClass
@BeforeAll
public static void retrieveApiKey() {
String apiKey = System.getenv("OPENWEATHER_API_KEY");
manager = new OpenWeatherMapClient(apiKey);
client = new OpenWeatherMapClient(apiKey);
}
protected static OpenWeatherMapClient getClient() {
return manager;
return client;
}
}
@@ -0,0 +1,105 @@
/*
* 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.enums;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class WeatherConditionUnitTest {
@Test
public void getId() {
final WeatherCondition weatherCondition = WeatherCondition.ASH;
assertNotEquals(0, weatherCondition.getId());
}
@Test
public void getName() {
final WeatherCondition weatherCondition = WeatherCondition.ASH;
assertNotNull(weatherCondition.getName());
assertNotEquals("", weatherCondition.getName());
}
@Test
public void getDescription() {
final WeatherCondition weatherCondition = WeatherCondition.ASH;
assertNotNull(weatherCondition.getDescription());
assertNotEquals("", weatherCondition.getDescription());
}
@Test
public void getDayIconId() {
final WeatherCondition weatherCondition = WeatherCondition.ASH;
assertNotNull(weatherCondition.getDayIconId());
assertNotEquals("", weatherCondition.getDayIconId());
}
@Test
public void getNightIconId() {
final WeatherCondition weatherCondition = WeatherCondition.ASH;
assertNotNull(weatherCondition.getNightIconId());
assertNotEquals("", weatherCondition.getNightIconId());
}
@Test
public void getDayIconUrl() {
final WeatherCondition weatherCondition = WeatherCondition.ASH;
assertNotNull(weatherCondition.getDayIconUrl());
assertNotEquals("", weatherCondition.getDayIconUrl());
}
@Test
public void getNightIconUrl() {
final WeatherCondition weatherCondition = WeatherCondition.ASH;
assertNotNull(weatherCondition.getNightIconUrl());
assertNotEquals("", weatherCondition.getNightIconUrl());
}
@Test
public void getIconUrl() {
final WeatherCondition weatherCondition = WeatherCondition.ASH;
assertNotNull(WeatherCondition.getIconUrl(weatherCondition.getNightIconId()));
assertNotEquals("", WeatherCondition.getIconUrl(weatherCondition.getNightIconId()));
}
@Test
public void getById() {
assertEquals(WeatherCondition.ASH, WeatherCondition.getById(WeatherCondition.ASH.getId()));
}
@Test
public void testToString() {
final WeatherCondition weatherCondition = WeatherCondition.ASH;
assertNotNull(weatherCondition.toString());
assertNotEquals("", weatherCondition.toString());
}
}
@@ -20,42 +20,21 @@
* 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;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class AtmosphericPressureUnitTest {
@Test
public void whenCreatePressureWithArgs_thenValueIsSet() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(100);
Assert.assertEquals(100, atmosphericPressure.getValue(), 0.00001);
assertEquals(100, atmosphericPressure.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);
assertEquals(0, AtmosphericPressure.withValue(0).getValue(), 0.00001);
assertEquals(100, AtmosphericPressure.withValue(100).getValue(), 0.00001);
assertEquals(55, AtmosphericPressure.withValue(55).getValue(), 0.00001);
}
@Test
@@ -63,9 +42,9 @@ public class AtmosphericPressureUnitTest {
AtmosphericPressure one = AtmosphericPressure.withValue(22);
AtmosphericPressure two = AtmosphericPressure.withValue(22);
Assert.assertTrue(one.equals(two));
Assert.assertTrue(one.equals(one));
Assert.assertEquals(one.hashCode(), two.hashCode());
assertEquals(one, two);
assertEquals(one, one);
assertEquals(one.hashCode(), two.hashCode());
one.setSeaLevelValue(333);
one.setGroundLevelValue(555);
@@ -73,9 +52,9 @@ public class AtmosphericPressureUnitTest {
two.setSeaLevelValue(333);
two.setGroundLevelValue(555);
Assert.assertTrue(one.equals(two));
Assert.assertTrue(two.equals(one));
Assert.assertEquals(one.hashCode(), two.hashCode());
assertEquals(one, two);
assertEquals(two, one);
assertEquals(one.hashCode(), two.hashCode());
}
@Test
@@ -83,23 +62,23 @@ public class AtmosphericPressureUnitTest {
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());
assertNotEquals(one, two);
assertNotEquals(two, one);
assertNotEquals(one, new Object());
assertNotEquals(one.hashCode(), two.hashCode());
one = AtmosphericPressure.withValue(44);
one.setSeaLevelValue(44);
two = AtmosphericPressure.withValue(44);
two.setGroundLevelValue(22);
Assert.assertFalse(one.equals(two));
Assert.assertFalse(two.equals(one));
assertNotEquals(one, two);
assertNotEquals(two, one);
two.setSeaLevelValue(44);
Assert.assertFalse(one.equals(two));
Assert.assertFalse(two.equals(one));
assertNotEquals(one, two);
assertNotEquals(two, one);
}
@Test
@@ -110,39 +89,42 @@ public class AtmosphericPressureUnitTest {
atmosphericPressure.setValue(100);
atmosphericPressure.setGroundLevelValue(222);
Assert.assertEquals(222, atmosphericPressure.getGroundLevelValue(), 0.00001);
assertEquals(222, atmosphericPressure.getGroundLevelValue(), 0.00001);
atmosphericPressure.setSeaLevelValue(4232);
Assert.assertEquals(4232, atmosphericPressure.getSeaLevelValue(), 0.00001);
assertEquals(4232, atmosphericPressure.getSeaLevelValue(), 0.00001);
}
@Test
public void whenCallToString_thenAllIsFine() {
final String pressureString = AtmosphericPressure.withValue(44).toString();
Assert.assertNotNull(pressureString);
Assert.assertNotEquals("", pressureString);
assertNotNull(pressureString);
assertNotEquals("", pressureString);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreatePressureByConstructorWithInvalidDataNegative_thenThrowAnException() {
AtmosphericPressure.withValue(-33);
assertThrows(IllegalArgumentException.class, () -> AtmosphericPressure.withValue(-33));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreatePressureAndSetInvalidDataNegative_thenThrowAnException() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88);
atmosphericPressure.setValue(-89);
assertThrows(IllegalArgumentException.class, () -> atmosphericPressure.setValue(-89));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidSeaLevelPressure_thenThrowAnException() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88);
atmosphericPressure.setSeaLevelValue(-89);
assertThrows(IllegalArgumentException.class, () -> atmosphericPressure.setSeaLevelValue(-89));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidGroundLevelPressure_thenThrowAnException() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88);
atmosphericPressure.setGroundLevelValue(-223);
assertThrows(IllegalArgumentException.class, () -> atmosphericPressure.setGroundLevelValue(-223));
}
}
@@ -20,75 +20,56 @@
* 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;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class CloudsUnitTest {
@Test
public void whenCreateCloudsWithValidArgs_thenValueIsSet() {
Clouds clouds = Clouds.withValue((byte) 100);
Assert.assertEquals(100, clouds.getValue());
assertEquals(100, clouds.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());
assertEquals(0, Clouds.withValue((byte) 0).getValue());
assertEquals(100, Clouds.withValue((byte) 100).getValue());
assertEquals(55, Clouds.withValue((byte) 55).getValue());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateCloudsByConstructorWithInvalidDataAboveHundred_thenThrowAnException() {
Clouds.withValue((byte) 110);
assertThrows(IllegalArgumentException.class, () -> Clouds.withValue((byte) 110));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateCloudsByConstructorWithInvalidDataNegative_thenThrowAnException() {
Clouds.withValue((byte) -33);
assertThrows(IllegalArgumentException.class, () -> Clouds.withValue((byte) -33));
}
@Test
public void whenSetValidValues_thenAllIsFine() {
Clouds clouds = Clouds.withValue((byte) 14);
clouds.setValue((byte) 0);
Assert.assertEquals(0, clouds.getValue());
assertEquals(0, clouds.getValue());
clouds.setValue((byte) 15);
Assert.assertEquals(15, clouds.getValue());
assertEquals(15, clouds.getValue());
clouds.setValue((byte) 100);
Assert.assertEquals(100, clouds.getValue());
assertEquals(100, clouds.getValue());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateCloudsAndSetInvalidDataAboveHundred_thenThrowAnException() {
Clouds clouds = Clouds.withValue((byte) 12);
clouds.setValue((byte) 112);
assertThrows(IllegalArgumentException.class, () -> clouds.setValue((byte) 112));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateCloudsAndSetInvalidDataNegative_thenThrowAnException() {
Clouds clouds = Clouds.withValue((byte) 88);
clouds.setValue((byte) -89);
assertThrows(IllegalArgumentException.class, () -> clouds.setValue((byte) -89));
}
@Test
@@ -96,9 +77,9 @@ public class CloudsUnitTest {
Clouds one = Clouds.withValue((byte) 22);
Clouds two = Clouds.withValue((byte) 22);
Assert.assertTrue(one.equals(two));
Assert.assertTrue(one.equals(one));
Assert.assertEquals(one.hashCode(), two.hashCode());
assertEquals(one, two);
assertEquals(one, one);
assertEquals(one.hashCode(), two.hashCode());
}
@Test
@@ -106,16 +87,16 @@ public class CloudsUnitTest {
Clouds one = Clouds.withValue((byte) 5);
Clouds two = Clouds.withValue((byte) 88);
Assert.assertFalse(one.equals(two));
Assert.assertFalse(two.equals(one));
Assert.assertFalse(one.equals(new Object()));
Assert.assertNotEquals(one.hashCode(), two.hashCode());
assertNotEquals(one, two);
assertNotEquals(two, one);
assertNotEquals(one, new Object());
assertNotEquals(one.hashCode(), two.hashCode());
}
@Test
public void whenCallToString_thenAllIsFine() {
final String cloudsString = Clouds.withValue((byte) 44).toString();
Assert.assertNotNull(cloudsString);
Assert.assertNotEquals("", cloudsString);
assertNotNull(cloudsString);
assertNotEquals("", cloudsString);
}
}
@@ -22,8 +22,9 @@
package com.github.prominence.openweathermap.api.model;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class CoordinateRectangleUnitTest {
@Test
@@ -31,102 +32,160 @@ public class CoordinateRectangleUnitTest {
CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectWithLatitudeBottomBelowMinus90_thenThrowAnException() {
CoordinateRectangle.withValues(44.5, -91.2, 54.4, 22.2);
assertThrows(IllegalArgumentException.class, () -> CoordinateRectangle.withValues(44.5, -91.2, 54.4, 22.2));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectWithLatitudeBottomAbove90_thenThrowAnException() {
CoordinateRectangle.withValues(44.5, 91.2, 54.4, 22.2);
assertThrows(IllegalArgumentException.class, () -> CoordinateRectangle.withValues(44.5, 91.2, 54.4, 22.2));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectWithLatitudeTopBelowMinus90_thenThrowAnException() {
CoordinateRectangle.withValues(44.5, 22.4, 54.4, -92.3);
assertThrows(IllegalArgumentException.class, () -> CoordinateRectangle.withValues(44.5, 22.4, 54.4, -92.3));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectWithLatitudeTopAbove90_thenThrowAnException() {
CoordinateRectangle.withValues(44.5, 22.5, 54.4, 94.887);
assertThrows(IllegalArgumentException.class, () -> CoordinateRectangle.withValues(44.5, 22.5, 54.4, 94.887));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectWithLongitudeLeftBelowMinus180_thenThrowAnException() {
CoordinateRectangle.withValues(-944.5, 22.4, 54.4, 22.2);
assertThrows(IllegalArgumentException.class, () -> CoordinateRectangle.withValues(-944.5, 22.4, 54.4, 22.2));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectWithLongitudeLeftAbove180_thenThrowAnException() {
CoordinateRectangle.withValues(544.5, 22.4, 54.4, 22.2);
assertThrows(IllegalArgumentException.class, () -> CoordinateRectangle.withValues(544.5, 22.4, 54.4, 22.2));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectWithLongitudeRightBelowMinus180_thenThrowAnException() {
CoordinateRectangle.withValues(44.5, 22.4, -254.4, 22.2);
assertThrows(IllegalArgumentException.class, () -> CoordinateRectangle.withValues(44.5, 22.4, -254.4, 22.2));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectWithLongitudeRightAbove180_thenThrowAnException() {
CoordinateRectangle.withValues(44.5, 22.4, 354.4, 22.2);
assertThrows(IllegalArgumentException.class, () -> CoordinateRectangle.withValues(44.5, 22.4, 354.4, 22.2));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectUsingBuilderWithInvalidLatitudeBottom_thenFail() {
new CoordinateRectangle.Builder()
.setLatitudeBottom(-1000);
assertThrows(IllegalArgumentException.class, () -> new CoordinateRectangle.Builder()
.setLatitudeBottom(-1000));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectUsingBuilderWithInvalidLatitudeBottom2_thenFail() {
assertThrows(IllegalArgumentException.class, () -> new CoordinateRectangle.Builder()
.setLatitudeBottom(1000));
}
@Test
public void whenCreateObjectUsingBuilderWithInvalidLatitudeTop_thenFail() {
new CoordinateRectangle.Builder()
.setLatitudeTop(-1000);
assertThrows(IllegalArgumentException.class, () -> new CoordinateRectangle.Builder()
.setLatitudeTop(-1000));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectUsingBuilderWithInvalidLatitudeTop2_thenFail() {
assertThrows(IllegalArgumentException.class, () -> new CoordinateRectangle.Builder()
.setLatitudeTop(1000));
}
@Test
public void whenCreateObjectUsingBuilderWithInvalidLongitudeLeft_thenFail() {
new CoordinateRectangle.Builder()
.setLongitudeLeft(-1000);
assertThrows(IllegalArgumentException.class, () -> new CoordinateRectangle.Builder()
.setLongitudeLeft(-1000));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectUsingBuilderWithInvalidLongitudeLeft2_thenFail() {
assertThrows(IllegalArgumentException.class, () -> new CoordinateRectangle.Builder()
.setLongitudeLeft(1000));
}
@Test
public void whenCreateObjectUsingBuilderWithInvalidLongitudeRight_thenFail() {
new CoordinateRectangle.Builder()
.setLongitudeRight(-1000);
assertThrows(IllegalArgumentException.class, () -> new CoordinateRectangle.Builder()
.setLongitudeRight(-1000));
}
@Test(expected = IllegalStateException.class)
@Test
public void whenCreateObjectUsingBuilderWithInvalidLongitudeRight2_thenFail() {
assertThrows(IllegalArgumentException.class, () -> new CoordinateRectangle.Builder()
.setLongitudeRight(1000));
}
@Test
public void whenCreateObjectUsingBuilderWithoutAllPropertiesSet_thenFail() {
new CoordinateRectangle.Builder()
assertThrows(IllegalStateException.class, () -> new CoordinateRectangle.Builder()
.build());
}
@Test
public void whenCreateObjectUsingBuilderWithoutAllPropertiesSet1_thenFail() {
assertThrows(IllegalStateException.class, () -> new CoordinateRectangle.Builder()
.setLongitudeLeft(10)
.build());
}
@Test
public void whenCreateObjectUsingBuilderWithoutAllPropertiesSet2_thenFail() {
assertThrows(IllegalStateException.class, () -> new CoordinateRectangle.Builder()
.setLongitudeRight(10)
.build();
.setLatitudeBottom(10)
.build());
}
@Test
public void whenCreateObjectUsingBuilderWithoutAllPropertiesSet3_thenFail() {
assertThrows(IllegalStateException.class, () -> new CoordinateRectangle.Builder()
.setLongitudeLeft(10)
.setLatitudeBottom(10)
.setLongitudeRight(10)
.build());
}
@Test
public void whenCreateObjectUsingBuilderWithoutAllPropertiesSet4_thenFail() {
assertThrows(IllegalStateException.class, () -> new CoordinateRectangle.Builder()
.setLongitudeLeft(10)
.setLatitudeTop(10)
.setLatitudeBottom(10)
.build());
}
@Test
public void whenCreateObjectUsingBuilderWithCorrectUsage_thenOk() {
new CoordinateRectangle.Builder()
final CoordinateRectangle rectangle = new CoordinateRectangle.Builder()
.setLongitudeRight(10)
.setLongitudeLeft(10)
.setLatitudeTop(10)
.setLatitudeBottom(10)
.build();
assertNotNull(rectangle);
}
@Test
public void whenGetAllParameters_thenAllIsFine() {
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);
Assert.assertEquals(22.2, rectangle.getLatitudeTop(), 0.00001);
assertEquals(44.5, rectangle.getLongitudeLeft(), 0.00001);
assertEquals(22.4, rectangle.getLatitudeBottom(), 0.00001);
assertEquals(54.4, rectangle.getLongitudeRight(), 0.00001);
assertEquals(22.2, rectangle.getLatitudeTop(), 0.00001);
}
@Test
public void whenCallToString_thenAllIsFine() {
final CoordinateRectangle rectangle = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
Assert.assertNotNull(rectangle.toString());
Assert.assertNotEquals("", rectangle.toString());
assertNotNull(rectangle.toString());
assertNotEquals("", rectangle.toString());
}
@Test
@@ -134,12 +193,12 @@ public class CoordinateRectangleUnitTest {
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());
assertEquals(first.hashCode(), second.hashCode());
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());
assertNotEquals(first.hashCode(), third.hashCode());
assertNotEquals(second.hashCode(), third.hashCode());
}
@Test
@@ -147,24 +206,24 @@ public class CoordinateRectangleUnitTest {
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()));
assertEquals(first, second);
assertEquals(first, first);
assertNotEquals(first, new Object());
first = CoordinateRectangle.withValues(49.5, 22.4, 54.4, 22.2);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
first = CoordinateRectangle.withValues(44.5, 29.4, 54.4, 22.2);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
first = CoordinateRectangle.withValues(44.5, 22.4, 24.4, 22.2);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, -2.2);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
}
}
@@ -22,148 +22,150 @@
package com.github.prominence.openweathermap.api.model;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class CoordinateUnitTest {
@Test
public void whenCreateCoordinateWithValidValues_thenObjectCreated() {
Coordinate.withValues(44, 53);
Coordinate.of(44, 53);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateCoordinateWithInvalidLatitudeBelowMinus90_thenThrowAnException() {
Coordinate.withValues(-333, 44);
assertThrows(IllegalArgumentException.class, () -> Coordinate.of(-333, 44));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateCoordinateWithInvalidLatitudeAbove90_thenThrowAnException() {
Coordinate.withValues(223, 44);
assertThrows(IllegalArgumentException.class, () -> Coordinate.of(223, 44));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateCoordinateWithInvalidLongitudeBelowMinus180_thenThrowAnException() {
Coordinate.withValues(33, -999);
assertThrows(IllegalArgumentException.class, () -> Coordinate.of(33, -999));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateCoordinateWithInvalidLongitudeAbove180_thenThrowAnException() {
Coordinate.withValues(33, 999);
assertThrows(IllegalArgumentException.class, () -> Coordinate.of(33, 999));
}
@Test
public void whenSetValidCoordinates_thenAllIsFine() {
final Coordinate coordinate = Coordinate.withValues(0, 0);
final Coordinate coordinate = Coordinate.of(0, 0);
coordinate.setLatitude(-90);
Assert.assertEquals(-90, coordinate.getLatitude(), 0.00001);
assertEquals(-90, coordinate.getLatitude(), 0.00001);
coordinate.setLatitude(90);
Assert.assertEquals(90, coordinate.getLatitude(), 0.00001);
assertEquals(90, coordinate.getLatitude(), 0.00001);
coordinate.setLatitude(44);
Assert.assertEquals(44, coordinate.getLatitude(), 0.00001);
assertEquals(44, coordinate.getLatitude(), 0.00001);
coordinate.setLongitude(-180);
Assert.assertEquals(-180, coordinate.getLongitude(), 0.00001);
assertEquals(-180, coordinate.getLongitude(), 0.00001);
coordinate.setLongitude(180);
Assert.assertEquals(180, coordinate.getLongitude(), 0.00001);
assertEquals(180, coordinate.getLongitude(), 0.00001);
coordinate.setLongitude(130);
Assert.assertEquals(130, coordinate.getLongitude(), 0.00001);
assertEquals(130, coordinate.getLongitude(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidLatitudeBelowMinus90_thenThrowAnException() {
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLatitude(-91);
final Coordinate coordinate = Coordinate.of(0, 0);
assertThrows(IllegalArgumentException.class, () -> coordinate.setLatitude(-91));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidLatitudeAbove90_thenThrowAnException() {
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLatitude(92);
final Coordinate coordinate = Coordinate.of(0, 0);
assertThrows(IllegalArgumentException.class, () -> coordinate.setLatitude(92));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidLongitudeBelowMinus180_thenThrowAnException() {
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLongitude(-194);
final Coordinate coordinate = Coordinate.of(0, 0);
assertThrows(IllegalArgumentException.class, () -> coordinate.setLongitude(-194));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidLongitudeAbove180_thenThrowAnException() {
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLongitude(444);
final Coordinate coordinate = Coordinate.of(0, 0);
assertThrows(IllegalArgumentException.class, () -> coordinate.setLongitude(444));
}
@Test
public void whenGetLatitude_thenAllIsFine() {
final Coordinate coordinate = Coordinate.withValues(0, 0);
Assert.assertEquals(0, coordinate.getLatitude(), 0.00001);
final Coordinate coordinate = Coordinate.of(0, 0);
assertEquals(0, coordinate.getLatitude(), 0.00001);
coordinate.setLatitude(45);
Assert.assertEquals(45, coordinate.getLatitude(), 0.00001);
assertEquals(45, coordinate.getLatitude(), 0.00001);
}
@Test
public void whenGetLongitude_thenAllIsFine() {
final Coordinate coordinate = Coordinate.withValues(0, 0);
Assert.assertEquals(0, coordinate.getLongitude(), 0.00001);
final Coordinate coordinate = Coordinate.of(0, 0);
assertEquals(0, coordinate.getLongitude(), 0.00001);
coordinate.setLongitude(33);
Assert.assertEquals(33, coordinate.getLongitude(), 0.00001);
assertEquals(33, coordinate.getLongitude(), 0.00001);
}
@Test
public void whenCallToString_thenAllIsFine() {
final Coordinate coordinate = Coordinate.withValues(0, 0);
Assert.assertNotNull(coordinate.toString());
Assert.assertNotEquals("", coordinate.toString());
final Coordinate coordinate = Coordinate.of(0, 0);
assertNotNull(coordinate.toString());
assertNotEquals("", coordinate.toString());
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final Coordinate first = Coordinate.withValues(22, 66);
final Coordinate second = Coordinate.withValues(22, 44);
final Coordinate first = Coordinate.of(22, 66);
final Coordinate second = Coordinate.of(22, 44);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
second.setLongitude(66);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
second.setLatitude(89);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
first.setLatitude(89);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
}
@Test
public void whenCheckEquality_thenAllIsFine() {
final Coordinate first = Coordinate.withValues(11, 99);
final Coordinate second = Coordinate.withValues(11, 99);
final Coordinate first = Coordinate.of(11, 99);
final Coordinate second = Coordinate.of(11, 99);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
Assert.assertFalse(first.equals(new Object()));
assertEquals(first, second);
assertEquals(first, first);
assertNotEquals(first, new Object());
first.setLatitude(34);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
second.setLatitude(34);
Assert.assertTrue(first.equals(second));
assertEquals(first, second);
second.setLongitude(74);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
first.setLongitude(74);
Assert.assertTrue(first.equals(second));
assertEquals(first, second);
}
}
@@ -22,13 +22,14 @@
package com.github.prominence.openweathermap.api.model;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DayTimeUnitTest {
@Test
public void whenGetValue_thenValueIsPresentAndValid() {
Assert.assertEquals("d", DayTime.DAY.getValue());
Assert.assertEquals("n", DayTime.NIGHT.getValue());
assertEquals("d", DayTime.DAY.getValue());
assertEquals("n", DayTime.NIGHT.getValue());
}
}
@@ -22,51 +22,52 @@
package com.github.prominence.openweathermap.api.model;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class HumidityUnitTest {
@Test
public void whenCreateHumidityWithArgs_thenValueIsSet() {
Humidity humidity = Humidity.withValue((byte) 100);
Assert.assertEquals(100, humidity.getValue());
assertEquals(100, humidity.getValue());
Assert.assertEquals(0, Humidity.withValue((byte) 0).getValue());
Assert.assertEquals(55, Humidity.withValue((byte) 55).getValue());
assertEquals(0, Humidity.withValue((byte) 0).getValue());
assertEquals(55, Humidity.withValue((byte) 55).getValue());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateHumidityByConstructorWithInvalidDataAboveHundred_thenThrowAnException() {
Humidity.withValue((byte) 112);
assertThrows(IllegalArgumentException.class, () -> Humidity.withValue((byte) 112));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateHumidityByConstructorWithInvalidDataNegative_thenThrowAnException() {
Humidity.withValue((byte) -33);
assertThrows(IllegalArgumentException.class, () -> Humidity.withValue((byte) -33));
}
@Test
public void whenSetValidValues_thenAllIsFine() {
Humidity humidity = Humidity.withValue((byte) 14);
Assert.assertEquals(14, humidity.getValue());
assertEquals(14, humidity.getValue());
humidity.setValue((byte) 0);
Assert.assertEquals(0, humidity.getValue());
assertEquals(0, humidity.getValue());
humidity.setValue((byte) 15);
Assert.assertEquals(15, humidity.getValue());
assertEquals(15, humidity.getValue());
humidity.setValue((byte) 100);
Assert.assertEquals(100, humidity.getValue());
assertEquals(100, humidity.getValue());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateHumidityAndSetInvalidDataAboveHundred_thenThrowAnException() {
Humidity humidity = Humidity.withValue((byte) 12);
humidity.setValue((byte) 112);
assertThrows(IllegalArgumentException.class, () -> humidity.setValue((byte) 112));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateHumidityAndSetInvalidDataNegative_thenThrowAnException() {
Humidity humidity = Humidity.withValue((byte) 88);
humidity.setValue((byte) -89);
assertThrows(IllegalArgumentException.class, () -> humidity.setValue((byte) -89));
}
@Test
@@ -74,9 +75,9 @@ public class HumidityUnitTest {
Humidity one = Humidity.withValue((byte) 22);
Humidity two = Humidity.withValue((byte) 22);
Assert.assertTrue(one.equals(two));
Assert.assertTrue(one.equals(one));
Assert.assertEquals(one.hashCode(), two.hashCode());
assertEquals(one, two);
assertEquals(one, one);
assertEquals(one.hashCode(), two.hashCode());
}
@Test
@@ -84,16 +85,16 @@ public class HumidityUnitTest {
Humidity one = Humidity.withValue((byte) 5);
Humidity two = Humidity.withValue((byte) 88);
Assert.assertFalse(one.equals(two));
Assert.assertFalse(two.equals(one));
Assert.assertFalse(one.equals(new Object()));
Assert.assertNotEquals(one.hashCode(), two.hashCode());
assertNotEquals(one, two);
assertNotEquals(two, one);
assertNotEquals(one, new Object());
assertNotEquals(one.hashCode(), two.hashCode());
}
@Test
public void whenCallToString_thenAllIsFine() {
final String humidityString = Humidity.withValue((byte) 44).toString();
Assert.assertNotNull(humidityString);
Assert.assertNotEquals("", humidityString);
assertNotNull(humidityString);
assertNotEquals("", humidityString);
}
}
@@ -22,8 +22,9 @@
package com.github.prominence.openweathermap.api.model;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class TemperatureUnitTest {
@Test
@@ -31,9 +32,9 @@ public class TemperatureUnitTest {
Temperature.withValue(22.2, "K");
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectWithEmptyUnit_thenThrowAnException() {
Temperature.withValue(22.2, null);
assertThrows(IllegalArgumentException.class, () -> Temperature.withValue(22.2, null));
}
@Test
@@ -41,7 +42,7 @@ public class TemperatureUnitTest {
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setValue(55.44);
Assert.assertEquals(55.44, temperature.getValue(), 0.00001);
assertEquals(55.44, temperature.getValue(), 0.00001);
}
@Test
@@ -49,11 +50,11 @@ public class TemperatureUnitTest {
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setMaxTemperature(44.4);
Assert.assertEquals(44.4, temperature.getMaxTemperature(), 0.00001);
assertEquals(44.4, temperature.getMaxTemperature(), 0.00001);
temperature.setMaxTemperature(null);
Assert.assertNull(temperature.getMaxTemperature());
assertNull(temperature.getMaxTemperature());
}
@Test
@@ -61,11 +62,11 @@ public class TemperatureUnitTest {
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setMinTemperature(33.2);
Assert.assertEquals(33.2, temperature.getMinTemperature(), 0.00001);
assertEquals(33.2, temperature.getMinTemperature(), 0.00001);
temperature.setMinTemperature(null);
Assert.assertNull(temperature.getMinTemperature());
assertNull(temperature.getMinTemperature());
}
@Test
@@ -73,11 +74,11 @@ public class TemperatureUnitTest {
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setFeelsLike(22.3);
Assert.assertEquals(22.3, temperature.getFeelsLike(), 0.00001);
assertEquals(22.3, temperature.getFeelsLike(), 0.00001);
temperature.setFeelsLike(null);
Assert.assertNull(temperature.getFeelsLike());
assertNull(temperature.getFeelsLike());
}
@Test
@@ -85,37 +86,37 @@ public class TemperatureUnitTest {
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setUnit("test");
Assert.assertTrue("test".equals(temperature.getUnit()));
assertEquals("test", temperature.getUnit());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetNullUnit_thenThrowAnException() {
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setUnit(null);
assertThrows(IllegalArgumentException.class, () -> temperature.setUnit(null));
}
@Test
public void whenCallToString_thenAllIsFine() {
final Temperature temperature = Temperature.withValue(22.2, "K");
Assert.assertNotNull(temperature.toString());
Assert.assertNotEquals("", temperature.toString());
assertNotNull(temperature.toString());
assertNotEquals("", temperature.toString());
temperature.setMinTemperature(11.2);
Assert.assertNotNull(temperature.toString());
Assert.assertNotEquals("", temperature.toString());
assertNotNull(temperature.toString());
assertNotEquals("", temperature.toString());
temperature.setMaxTemperature(44.3);
Assert.assertNotNull(temperature.toString());
Assert.assertNotEquals("", temperature.toString());
assertNotNull(temperature.toString());
assertNotEquals("", temperature.toString());
temperature.setFeelsLike(22.4);
Assert.assertNotNull(temperature.toString());
Assert.assertNotEquals("", temperature.toString());
assertNotNull(temperature.toString());
assertNotEquals("", temperature.toString());
}
@Test
@@ -123,7 +124,7 @@ public class TemperatureUnitTest {
final Temperature one = Temperature.withValue(22.2, "K");
final Temperature two = Temperature.withValue(22.2, "K");
Assert.assertEquals(one.hashCode(), two.hashCode());
assertEquals(one.hashCode(), two.hashCode());
}
@Test
@@ -131,44 +132,44 @@ public class TemperatureUnitTest {
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()));
Assert.assertFalse(one.equals(two));
assertEquals(one, one);
assertNotEquals(one, new Object());
assertNotEquals(one, two);
one.setValue(21.2);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setMaxTemperature(33.56);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setMaxTemperature(33.56);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setMinTemperature(11.54);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setMinTemperature(11.54);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
two.setUnit("U");
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
one.setUnit("U");
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setFeelsLike(22.3);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setFeelsLike(22.3);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
}
}
@@ -0,0 +1,126 @@
/*
* 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 com.github.prominence.openweathermap.api.enums.WeatherCondition;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class WeatherStateUnitTest {
@Test
public void getId() {
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
assertEquals(800, weatherState.getId());
}
@Test
public void getName() {
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
assertEquals("Clear", weatherState.getName());
}
@Test
public void getDescription() {
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
assertEquals("clear sky", weatherState.getDescription());
}
@Test
public void getIconId() {
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
weatherState.setIconId("04d");
assertEquals("04d", weatherState.getIconId());
}
@Test
public void getWeatherConditionEnum() {
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
assertEquals(WeatherCondition.CLEAR, weatherState.getWeatherConditionEnum());
}
@Test
public void getWeatherIconUrl() {
WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
String weatherIconUrl = weatherState.getWeatherIconUrl();
assertNotNull(weatherIconUrl);
assertNotEquals("", weatherIconUrl);
weatherState.setIconId("04n");
weatherIconUrl = weatherState.getWeatherIconUrl();
assertNotNull(weatherIconUrl);
assertNotEquals("", weatherIconUrl);
weatherState = new WeatherState(0, "Unknown", "unknown");
weatherIconUrl = weatherState.getWeatherIconUrl();
assertNull(weatherIconUrl);
}
@Test
public void testEquals() {
final WeatherState first = new WeatherState(800, "Clear", "clear sky");
final WeatherState second = new WeatherState(800, "Clear", "clear sky");
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
assertEquals(first, second);
assertNotEquals(new WeatherState(800, "Clear", "clear sky"), new WeatherState(801, "Clear", "clear sky"));
assertNotEquals(new WeatherState(800, "Clear", "clear sky"), new WeatherState(800, "Clear1", "clear sky"));
assertNotEquals(new WeatherState(800, "Clear", "clear sky"), new WeatherState(800, "Clear", "clear sky1"));
first.setIconId("50d");
assertNotEquals(first, second);
}
@Test
public void testHashCode() {
final WeatherState first = new WeatherState(800, "Clear", "clear sky");
final WeatherState second = new WeatherState(800, "Clear", "clear sky");
final WeatherState third = new WeatherState(0, "Unknown", "unknown");
assertEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), third.hashCode());
assertNotEquals(second.hashCode(), third.hashCode());
}
@Test
public void testToString() {
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
assertNotNull(weatherState.toString());
assertNotEquals("", weatherState.toString());
}
}
@@ -22,18 +22,19 @@
package com.github.prominence.openweathermap.api.model.forecast;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.*;
public class ForecastUnitTest {
@Test
public void whenLocationIsSet_thenAllIsOk() {
final Forecast forecast = new Forecast();
forecast.setLocation(Location.withValues(2, "asd"));
Assert.assertNotNull(forecast.getLocation());
assertNotNull(forecast.getLocation());
}
@Test
@@ -41,7 +42,7 @@ public class ForecastUnitTest {
final Forecast forecast = new Forecast();
forecast.setWeatherForecasts(new ArrayList<>());
Assert.assertNotNull(forecast.getWeatherForecasts());
assertNotNull(forecast.getWeatherForecasts());
}
@Test
@@ -49,11 +50,11 @@ public class ForecastUnitTest {
final Forecast one = new Forecast();
final Forecast two = new Forecast();
Assert.assertEquals(one.hashCode(), two.hashCode());
assertEquals(one.hashCode(), two.hashCode());
one.setLocation(Location.withValues(22, "444"));
Assert.assertNotEquals(one.hashCode(), two.hashCode());
assertNotEquals(one.hashCode(), two.hashCode());
}
@Test
@@ -61,21 +62,21 @@ public class ForecastUnitTest {
final Forecast one = new Forecast();
final Forecast two = new Forecast();
Assert.assertTrue(one.equals(one));
Assert.assertFalse(one.equals(null));
Assert.assertTrue(one.equals(two));
Assert.assertFalse(one.equals(new Object()));
assertEquals(one, one);
assertNotEquals(one, null);
assertEquals(one, two);
assertNotEquals(one, new Object());
one.setLocation(Location.withValues(22, "234"));
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setLocation(one.getLocation());
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setWeatherForecasts(new ArrayList<>());
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
}
}
@@ -23,21 +23,22 @@
package com.github.prominence.openweathermap.api.model.forecast;
import com.github.prominence.openweathermap.api.model.Coordinate;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import static org.junit.jupiter.api.Assertions.*;
public class LocationUnitTest {
@Test
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
Location.withValues(33, "test");
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectWithoutName_thenThrowAnException() {
Location.withValues(33, null);
assertThrows(IllegalArgumentException.class, () -> Location.withValues(33, null));
}
@Test
@@ -45,7 +46,7 @@ public class LocationUnitTest {
final Location location = Location.withValues(33, "test");
location.setId(55);
Assert.assertEquals(55, location.getId());
assertEquals(55, location.getId());
}
@Test
@@ -53,7 +54,7 @@ public class LocationUnitTest {
final Location location = Location.withValues(33, "test");
location.setName("city");
Assert.assertEquals("city", location.getName());
assertEquals("city", location.getName());
}
@Test
@@ -61,25 +62,25 @@ public class LocationUnitTest {
final Location location = Location.withValues(33, "test");
location.setCountryCode("by");
Assert.assertEquals("by", location.getCountryCode());
assertEquals("by", location.getCountryCode());
}
@Test
public void whenSetSunrise_thenValueIsSet() {
final Location location = Location.withValues(33, "test");
final LocalDateTime now = LocalDateTime.now();
location.setSunrise(now);
location.setSunriseTime(now);
Assert.assertEquals(now, location.getSunrise());
assertEquals(now, location.getSunriseTime());
}
@Test
public void whenSetSunset_thenValueIsSet() {
final Location location = Location.withValues(33, "test");
final LocalDateTime now = LocalDateTime.now();
location.setSunset(now);
location.setSunsetTime(now);
Assert.assertEquals(now, location.getSunset());
assertEquals(now, location.getSunsetTime());
}
@Test
@@ -88,16 +89,16 @@ public class LocationUnitTest {
final ZoneOffset offset = ZoneOffset.UTC;
location.setZoneOffset(offset);
Assert.assertEquals(offset, location.getZoneOffset());
assertEquals(offset, location.getZoneOffset());
}
@Test
public void whenSetCoordinate_thenValueIsSet() {
final Location location = Location.withValues(33, "test");
final Coordinate coordinate = Coordinate.withValues(33.2, 64.2);
final Coordinate coordinate = Coordinate.of(33.2, 64.2);
location.setCoordinate(coordinate);
Assert.assertEquals(coordinate, location.getCoordinate());
assertEquals(coordinate, location.getCoordinate());
}
@Test
@@ -105,27 +106,27 @@ public class LocationUnitTest {
final Location location = Location.withValues(33, "test");
location.setPopulation(3444L);
Assert.assertEquals(3444L, location.getPopulation().longValue());
assertEquals(3444L, location.getPopulation().longValue());
}
@Test
public void whenCallToString_thenAllIsFine() {
final Location location = Location.withValues(44, "test");
Assert.assertNotEquals("", location.toString());
assertNotEquals("", location.toString());
location.setCoordinate(Coordinate.withValues(33.2, 56.3));
location.setCoordinate(Coordinate.of(33.2, 56.3));
Assert.assertNotEquals("", location.toString());
assertNotEquals("", location.toString());
location.setCountryCode("TN");
Assert.assertNotEquals("", location.toString());
Assert.assertNotNull(location.toString());
assertNotEquals("", location.toString());
assertNotNull(location.toString());
location.setPopulation(34343L);
Assert.assertNotEquals("", location.toString());
Assert.assertNotNull(location.toString());
assertNotEquals("", location.toString());
assertNotNull(location.toString());
}
@Test
@@ -133,11 +134,11 @@ public class LocationUnitTest {
final Location one = Location.withValues(44, "test");
final Location two = Location.withValues(44, "test");
Assert.assertEquals(one.hashCode(), two.hashCode());
assertEquals(one.hashCode(), two.hashCode());
two.setName("112");
Assert.assertNotEquals(one.hashCode(), two.hashCode());
assertNotEquals(one.hashCode(), two.hashCode());
}
@Test
@@ -145,77 +146,77 @@ public class LocationUnitTest {
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()));
assertEquals(one, one);
assertNotEquals(one, new Object());
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
two.setId(23);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
one.setId(23);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setName("23");
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setName("23");
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setCountryCode("11");
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setCountryCode("11");
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
final LocalDateTime now = LocalDateTime.now();
one.setSunrise(now);
one.setSunriseTime(now);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setSunrise(now);
two.setSunriseTime(now);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setSunset(now);
one.setSunsetTime(now);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setSunset(now);
two.setSunsetTime(now);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setZoneOffset(ZoneOffset.UTC);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setZoneOffset(ZoneOffset.UTC);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
final Coordinate coordinate = Coordinate.withValues(33.5, -22.4);
final Coordinate coordinate = Coordinate.of(33.5, -22.4);
one.setCoordinate(coordinate);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setCoordinate(coordinate);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setPopulation(20000L);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setPopulation(20000L);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
}
}
@@ -22,8 +22,9 @@
package com.github.prominence.openweathermap.api.model.forecast;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class RainUnitTest {
@Test
@@ -32,34 +33,34 @@ public class RainUnitTest {
Rain.withThreeHourLevelValue(0);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateWithInvalidData_thenFail() {
Rain.withThreeHourLevelValue(-20);
assertThrows(IllegalArgumentException.class, () -> Rain.withThreeHourLevelValue(-20));
}
@Test
public void whenSetValues_thenTheyAreSet() {
final Rain rain = Rain.withThreeHourLevelValue(0);
Assert.assertEquals(0, rain.getThreeHourRainLevel(), 0.00001);
assertEquals(0, rain.getThreeHourLevel(), 0.00001);
rain.setThreeHourRainLevel(55.5);
Assert.assertEquals(55.5, rain.getThreeHourRainLevel(), 0.00001);
rain.setThreeHourLevel(55.5);
assertEquals(55.5, rain.getThreeHourLevel(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidValue_thenFail() {
final Rain rain = Rain.withThreeHourLevelValue(0);
rain.setThreeHourRainLevel(-20);
assertThrows(IllegalArgumentException.class, () -> rain.setThreeHourLevel(-20));
}
@Test
public void whenCallToString_thenAllIsFine() {
final Rain rain = Rain.withThreeHourLevelValue(33.5);
Assert.assertNotNull(rain.toString());
Assert.assertNotEquals("", rain.toString());
assertNotNull(rain.toString());
assertNotEquals("", rain.toString());
}
@Test
@@ -67,15 +68,15 @@ public class RainUnitTest {
final Rain first = Rain.withThreeHourLevelValue(0);
final Rain second = Rain.withThreeHourLevelValue(0);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
second.setThreeHourRainLevel(11.0);
second.setThreeHourLevel(11.0);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
first.setThreeHourRainLevel(11.0);
first.setThreeHourLevel(11.0);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
}
@Test
@@ -83,16 +84,16 @@ public class RainUnitTest {
final Rain first = Rain.withThreeHourLevelValue(0);
final Rain second = Rain.withThreeHourLevelValue(0);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
Assert.assertFalse(first.equals(new Object()));
assertEquals(first, second);
assertEquals(first, first);
assertNotEquals(first, new Object());
second.setThreeHourRainLevel(66.7);
second.setThreeHourLevel(66.7);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
first.setThreeHourRainLevel(66.7);
first.setThreeHourLevel(66.7);
Assert.assertTrue(first.equals(second));
assertEquals(first, second);
}
}
@@ -22,8 +22,9 @@
package com.github.prominence.openweathermap.api.model.forecast;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class SnowUnitTest {
@Test
@@ -31,34 +32,34 @@ public class SnowUnitTest {
Snow.withThreeHourLevelValue(2222.3);
Snow.withThreeHourLevelValue(0);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateWithInvalidData_thenFail() {
Snow.withThreeHourLevelValue(-20);
assertThrows(IllegalArgumentException.class, () -> Snow.withThreeHourLevelValue(-20));
}
@Test
public void whenSetValues_thenTheyAreSet() {
final Snow snow = Snow.withThreeHourLevelValue(0);
Assert.assertEquals(0, snow.getThreeHourSnowLevel(), 0.00001);
assertEquals(0, snow.getThreeHourLevel(), 0.00001);
snow.setThreeHourSnowLevel(55.5);
Assert.assertEquals(55.5, snow.getThreeHourSnowLevel(), 0.00001);
snow.setThreeHourLevel(55.5);
assertEquals(55.5, snow.getThreeHourLevel(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidValue_thenFail() {
final Snow snow = Snow.withThreeHourLevelValue(0);
snow.setThreeHourSnowLevel(-20);
assertThrows(IllegalArgumentException.class, () -> snow.setThreeHourLevel(-20));
}
@Test
public void whenCallToString_thenAllIsFine() {
final Snow snow = Snow.withThreeHourLevelValue(33.5);
Assert.assertNotNull(snow.toString());
Assert.assertNotEquals("", snow.toString());
assertNotNull(snow.toString());
assertNotEquals("", snow.toString());
}
@Test
@@ -66,15 +67,15 @@ public class SnowUnitTest {
final Snow first = Snow.withThreeHourLevelValue(0);
final Snow second = Snow.withThreeHourLevelValue(0);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
second.setThreeHourSnowLevel(11.0);
second.setThreeHourLevel(11.0);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
first.setThreeHourSnowLevel(11.0);
first.setThreeHourLevel(11.0);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
}
@Test
@@ -82,16 +83,16 @@ public class SnowUnitTest {
final Snow first = Snow.withThreeHourLevelValue(0);
final Snow second = Snow.withThreeHourLevelValue(0);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
Assert.assertFalse(first.equals(new Object()));
assertEquals(first, second);
assertEquals(first, first);
assertNotEquals(first, new Object());
second.setThreeHourSnowLevel(66.7);
second.setThreeHourLevel(66.7);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
first.setThreeHourSnowLevel(66.7);
first.setThreeHourLevel(66.7);
Assert.assertTrue(first.equals(second));
assertEquals(first, second);
}
}
@@ -23,343 +23,287 @@
package com.github.prominence.openweathermap.api.model.forecast;
import com.github.prominence.openweathermap.api.model.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.*;
public class WeatherForecastUnitTest {
@Test
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
WeatherForecast.forValue("state", "desc");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithoutState_thenThrowAnException() {
WeatherForecast.forValue(null, "desc");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithoutDescription_thenThrowAnException() {
WeatherForecast.forValue("state", null);
}
@Test
public void whenSetState_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
weatherForecast.setState("test");
Assert.assertEquals("test", weatherForecast.getState());
}
@Test(expected = IllegalArgumentException.class)
public void whenSetNullState_thenThrowAnException() {
final WeatherForecast weather = WeatherForecast.forValue("state", "desc");
weather.setState(null);
}
@Test
public void whenSetDescription_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
weatherForecast.setDescription("test");
Assert.assertEquals("test", weatherForecast.getDescription());
}
@Test(expected = IllegalArgumentException.class)
public void whenSetNullDescription_thenThrowAnException() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
weatherForecast.setDescription(null);
}
@Test
public void whenSetIconId_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
Assert.assertNull(weatherForecast.getWeatherIconId());
Assert.assertNull(weatherForecast.getWeatherIconUrl());
weatherForecast.setWeatherIconId("02n");
Assert.assertEquals("02n", weatherForecast.getWeatherIconId());
Assert.assertNotNull(weatherForecast.getWeatherIconUrl());
}
@Test
public void whenSetForecastTime_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final WeatherForecast weatherForecast = new WeatherForecast();
final LocalDateTime now = LocalDateTime.now();
weatherForecast.setForecastTime(now);
Assert.assertEquals(now, weatherForecast.getForecastTime());
assertEquals(now, weatherForecast.getForecastTime());
}
@Test
public void whenSetTemperature_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final WeatherForecast weatherForecast = new WeatherForecast();
final Temperature temperature = Temperature.withValue(22.3, "a");
weatherForecast.setTemperature(temperature);
Assert.assertEquals(temperature, weatherForecast.getTemperature());
assertEquals(temperature, weatherForecast.getTemperature());
}
@Test
public void whenSetPressure_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final WeatherForecast weatherForecast = new WeatherForecast();
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.2);
weatherForecast.setAtmosphericPressure(atmosphericPressure);
Assert.assertEquals(atmosphericPressure, weatherForecast.getAtmosphericPressure());
assertEquals(atmosphericPressure, weatherForecast.getAtmosphericPressure());
}
@Test
public void whenSetHumidity_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final WeatherForecast weatherForecast = new WeatherForecast();
final Humidity humidity = Humidity.withValue((byte) 44);
weatherForecast.setHumidity(humidity);
Assert.assertEquals(humidity, weatherForecast.getHumidity());
assertEquals(humidity, weatherForecast.getHumidity());
}
@Test
public void whenSetWind_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final WeatherForecast weatherForecast = new WeatherForecast();
final Wind wind = Wind.withValue(22.2, "a");
weatherForecast.setWind(wind);
Assert.assertEquals(wind, weatherForecast.getWind());
assertEquals(wind, weatherForecast.getWind());
}
@Test
public void whenSetRain_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final WeatherForecast weatherForecast = new WeatherForecast();
final Rain rain = Rain.withThreeHourLevelValue(0);
weatherForecast.setRain(rain);
Assert.assertEquals(rain, weatherForecast.getRain());
assertEquals(rain, weatherForecast.getRain());
}
@Test
public void whenSetSnow_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final WeatherForecast weatherForecast = new WeatherForecast();
final Snow snow = Snow.withThreeHourLevelValue(0);
weatherForecast.setSnow(snow);
Assert.assertEquals(snow, weatherForecast.getSnow());
assertEquals(snow, weatherForecast.getSnow());
}
@Test
public void whenSetClouds_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final WeatherForecast weatherForecast = new WeatherForecast();
final Clouds clouds = Clouds.withValue((byte) 33);
weatherForecast.setClouds(clouds);
Assert.assertEquals(clouds, weatherForecast.getClouds());
assertEquals(clouds, weatherForecast.getClouds());
}
@Test
public void whenSetForecastTimeISO_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final WeatherForecast weatherForecast = new WeatherForecast();
Assert.assertNull(weatherForecast.getForecastTimeISO());
assertNull(weatherForecast.getForecastTimeISO());
weatherForecast.setForecastTimeISO("1994-2-3");
Assert.assertEquals("1994-2-3", weatherForecast.getForecastTimeISO());
assertEquals("1994-2-3", weatherForecast.getForecastTimeISO());
}
@Test
public void whenSetDayTime_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final WeatherForecast weatherForecast = new WeatherForecast();
Assert.assertNull(weatherForecast.getDayTime());
assertNull(weatherForecast.getDayTime());
weatherForecast.setDayTime(DayTime.DAY);
Assert.assertEquals(DayTime.DAY, weatherForecast.getDayTime());
assertEquals(DayTime.DAY, weatherForecast.getDayTime());
}
@Test
public void whenCallToString_thenAllIsFine() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final WeatherForecast weatherForecast = new WeatherForecast();
final Location location = Location.withValues(12312, "asd");
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
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());
assertNotEquals("", weatherForecast.toString());
assertNotNull(weatherForecast.toString());
weatherForecast.setWeatherState(weatherState);
assertNotEquals("", weatherForecast.toString());
assertNotNull(weatherForecast.toString());
location.setCountryCode("3d");
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
assertNotEquals("", weatherForecast.toString());
assertNotNull(weatherForecast.toString());
weatherForecast.setTemperature(temperature);
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
assertNotEquals("", weatherForecast.toString());
assertNotNull(weatherForecast.toString());
weatherForecast.setAtmosphericPressure(atmosphericPressure);
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
assertNotEquals("", weatherForecast.toString());
assertNotNull(weatherForecast.toString());
weatherForecast.setClouds(clouds);
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
assertNotEquals("", weatherForecast.toString());
assertNotNull(weatherForecast.toString());
weatherForecast.setRain(rain);
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
assertNotEquals("", weatherForecast.toString());
assertNotNull(weatherForecast.toString());
weatherForecast.setSnow(snow);
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
assertNotEquals("", weatherForecast.toString());
assertNotNull(weatherForecast.toString());
weatherForecast.setRain(null);
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
assertNotEquals("", weatherForecast.toString());
assertNotNull(weatherForecast.toString());
weatherForecast.setSnow(null);
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
assertNotEquals("", weatherForecast.toString());
assertNotNull(weatherForecast.toString());
weatherForecast.setRain(Rain.withThreeHourLevelValue(0));
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
assertNotEquals("", weatherForecast.toString());
assertNotNull(weatherForecast.toString());
weatherForecast.setSnow(Snow.withThreeHourLevelValue(0));
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
assertNotEquals("", weatherForecast.toString());
assertNotNull(weatherForecast.toString());
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final WeatherForecast one = WeatherForecast.forValue("state", "desc");
final WeatherForecast two = WeatherForecast.forValue("state", "desc");
final WeatherForecast first = new WeatherForecast();
final WeatherForecast second = new WeatherForecast();
Assert.assertEquals(one.hashCode(), two.hashCode());
assertEquals(first.hashCode(), second.hashCode());
two.setDescription("112");
second.setDayTime(DayTime.NIGHT);
Assert.assertNotEquals(one.hashCode(), two.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void whenCheckEquality_thenAllIsFine() {
final WeatherForecast one = WeatherForecast.forValue("state", "desc");
final WeatherForecast two = WeatherForecast.forValue("state1", "desc1");
final WeatherForecast first = new WeatherForecast();
final WeatherForecast second = new WeatherForecast();
Assert.assertTrue(one.equals(one));
Assert.assertFalse(one.equals(null));
Assert.assertFalse(one.equals(new Object()));
Assert.assertFalse(one.equals(two));
two.setState("state");
Assert.assertFalse(one.equals(two));
two.setDescription("desc");
Assert.assertTrue(one.equals(two));
one.setWeatherIconId("1");
Assert.assertFalse(one.equals(two));
two.setWeatherIconId("1");
Assert.assertTrue(one.equals(two));
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
assertEquals(first, second);
final LocalDateTime now = LocalDateTime.now();
one.setForecastTime(now);
first.setForecastTime(now);
Assert.assertFalse(one.equals(two));
assertNotEquals(first, second);
two.setForecastTime(now);
second.setForecastTime(now);
Assert.assertTrue(one.equals(two));
assertEquals(first, second);
final Temperature temperature = Temperature.withValue(33.2, "as");
one.setTemperature(temperature);
first.setTemperature(temperature);
Assert.assertFalse(one.equals(two));
assertNotEquals(first, second);
two.setTemperature(temperature);
second.setTemperature(temperature);
Assert.assertTrue(one.equals(two));
assertEquals(first, second);
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
first.setWeatherState(weatherState);
assertNotEquals(first, second);
second.setWeatherState(weatherState);
assertEquals(first, second);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.33);
one.setAtmosphericPressure(atmosphericPressure);
first.setAtmosphericPressure(atmosphericPressure);
Assert.assertFalse(one.equals(two));
assertNotEquals(first, second);
two.setAtmosphericPressure(atmosphericPressure);
second.setAtmosphericPressure(atmosphericPressure);
Assert.assertTrue(one.equals(two));
assertEquals(first, second);
final Humidity humidity = Humidity.withValue((byte) 33);
one.setHumidity(humidity);
first.setHumidity(humidity);
Assert.assertFalse(one.equals(two));
assertNotEquals(first, second);
two.setHumidity(humidity);
second.setHumidity(humidity);
Assert.assertTrue(one.equals(two));
assertEquals(first, second);
final Wind wind = Wind.withValue(33.6, "asd");
one.setWind(wind);
first.setWind(wind);
Assert.assertFalse(one.equals(two));
assertNotEquals(first, second);
two.setWind(wind);
second.setWind(wind);
Assert.assertTrue(one.equals(two));
assertEquals(first, second);
final Rain rain = Rain.withThreeHourLevelValue(0);
one.setRain(rain);
first.setRain(rain);
Assert.assertFalse(one.equals(two));
assertNotEquals(first, second);
two.setRain(rain);
second.setRain(rain);
Assert.assertTrue(one.equals(two));
assertEquals(first, second);
final Snow snow = Snow.withThreeHourLevelValue(0);
one.setSnow(snow);
first.setSnow(snow);
Assert.assertFalse(one.equals(two));
assertNotEquals(first, second);
two.setSnow(snow);
second.setSnow(snow);
Assert.assertTrue(one.equals(two));
assertEquals(first, second);
final Clouds clouds = Clouds.withValue((byte) 33);
one.setClouds(clouds);
first.setClouds(clouds);
Assert.assertFalse(one.equals(two));
assertNotEquals(first, second);
two.setClouds(clouds);
second.setClouds(clouds);
Assert.assertTrue(one.equals(two));
assertEquals(first, second);
one.setForecastTimeISO("test");
first.setForecastTimeISO("test");
Assert.assertFalse(one.equals(two));
assertNotEquals(first, second);
two.setForecastTimeISO("test");
second.setForecastTimeISO("test");
Assert.assertTrue(one.equals(two));
assertEquals(first, second);
one.setDayTime(DayTime.NIGHT);
first.setDayTime(DayTime.NIGHT);
Assert.assertFalse(one.equals(two));
assertNotEquals(first, second);
two.setDayTime(DayTime.DAY);
second.setDayTime(DayTime.DAY);
Assert.assertFalse(one.equals(two));
assertNotEquals(first, second);
one.setDayTime(DayTime.DAY);
first.setDayTime(DayTime.DAY);
Assert.assertTrue(one.equals(two));
assertEquals(first, second);
}
}
@@ -22,108 +22,109 @@
package com.github.prominence.openweathermap.api.model.forecast;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class WindUnitTest {
@Test
public void whenCreateWindWithValidArgs_thenValueIsSet() {
Assert.assertEquals(44.0, Wind.withValue(44, "ms").getSpeed(), 0.00001);
assertEquals(44.0, Wind.withValue(44, "ms").getSpeed(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateWindWithInvalidSpeedArg_thenThrowAnException() {
Wind.withValue(-21, "a");
assertThrows(IllegalArgumentException.class, () -> Wind.withValue(-21, "a"));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateWindWithInvalidUnitArg_thenThrowAnException() {
Wind.withValue(342, null);
assertThrows(IllegalArgumentException.class, () -> Wind.withValue(342, null));
}
@Test
public void whenSetValidSpeed_thenValueIsSet() {
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
assertEquals(33, wind.getSpeed(), 0.00001);
wind.setSpeed(0);
Assert.assertEquals(0, wind.getSpeed(), 0.00001);
assertEquals(0, wind.getSpeed(), 0.00001);
wind.setSpeed(3656);
Assert.assertEquals(3656, wind.getSpeed(), 0.00001);
assertEquals(3656, wind.getSpeed(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidSpeedBelow0_thenThrowAnException() {
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
assertEquals(33, wind.getSpeed(), 0.00001);
wind.setSpeed(-22);
assertThrows(IllegalArgumentException.class, () -> wind.setSpeed(-22));
}
@Test
public void whenSetValidDegrees_thenValueIsSet() {
final Wind wind = Wind.withValue(33, "as");
Assert.assertNull(wind.getDegrees());
assertNull(wind.getDegrees());
wind.setDegrees(22);
Assert.assertEquals(22, wind.getDegrees(), 0.00001);
assertEquals(22, wind.getDegrees(), 0.00001);
wind.setDegrees(0);
Assert.assertEquals(0, wind.getDegrees(), 0.00001);
assertEquals(0, wind.getDegrees(), 0.00001);
wind.setDegrees(360);
Assert.assertEquals(360, wind.getDegrees(), 0.00001);
assertEquals(360, wind.getDegrees(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidDegreesBelow0_thenThrowAnException() {
final Wind wind = Wind.withValue(33, "as");
wind.setDegrees(-32);
assertThrows(IllegalArgumentException.class, () -> wind.setDegrees(-32));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidDegreesAbove360_thenThrowAnException() {
final Wind wind = Wind.withValue(33, "as");
wind.setDegrees(378);
assertThrows(IllegalArgumentException.class, () -> wind.setDegrees(378));
}
@Test
public void whenSetNonNullUnit_thenValueIsSet() {
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(wind.getUnit(), "as");
assertEquals(wind.getUnit(), "as");
wind.setUnit("myUnit");
Assert.assertEquals(wind.getUnit(), "myUnit");
assertEquals(wind.getUnit(), "myUnit");
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetNullUnit_thenThrowAnException() {
final Wind wind = Wind.withValue(33, "as");
wind.setUnit(null);
assertThrows(IllegalArgumentException.class, () -> wind.setUnit(null));
}
@Test
public void whenCallToString_thenAllIsFine() {
final Wind wind = Wind.withValue(302, "a");
Assert.assertNotNull(wind.toString());
assertNotNull(wind.toString());
wind.setDegrees(22);
Assert.assertNotNull(wind.toString());
Assert.assertNotEquals("", wind.toString());
assertNotNull(wind.toString());
assertNotEquals("", wind.toString());
}
@Test
@@ -131,49 +132,55 @@ public class WindUnitTest {
final Wind first = Wind.withValue(22, "a");
final Wind second = Wind.withValue(22, "b");
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
second.setUnit("a");
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
second.setSpeed(33);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
first.setSpeed(333);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
first.setSpeed(33);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
}
@Test
public void whenCheckEquality_thenAllIsFine() {
final Wind first = Wind.withValue(11, "a");
final Wind second = Wind.withValue(11, "a");
final Wind second = Wind.withValue(12, "a");
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
Assert.assertFalse(first.equals(new Object()));
assertNotEquals(first, second);
first.setSpeed(12);
assertEquals(first, second);
assertEquals(first, first);
assertNotEquals(first, new Object());
first.setDegrees(34);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
second.setDegrees(34);
Assert.assertTrue(first.equals(second));
assertEquals(first, second);
second.setUnit("v");
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
first.setUnit("v");
assertEquals(first, second);
first.setSpeed(second.getSpeed() + 4);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
}
}
@@ -0,0 +1,85 @@
/*
* 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.onecall;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class AtmosphericPressureUnitTest {
@Test
public void withInvalidValue_negative() {
assertThrows(IllegalArgumentException.class, () -> AtmosphericPressure.withValue(-20.0));
}
@Test
public void getSeaLevelValue() {
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(22.2);
assertEquals(22.2, atmosphericPressure.getSeaLevelValue(), 0.00001);
}
@Test
public void getUnit() {
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(22.2);
assertNotNull(atmosphericPressure.getUnit());
assertNotEquals("", atmosphericPressure.getUnit());
}
@Test
public void testEquals() {
final AtmosphericPressure first = AtmosphericPressure.withValue(600);
final AtmosphericPressure second = AtmosphericPressure.withValue(600);
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
assertEquals(first, second);
first.setSeaLevelValue(200);
assertNotEquals(first, second);
}
@Test
public void testHashCode() {
final AtmosphericPressure first = AtmosphericPressure.withValue(600);
final AtmosphericPressure second = AtmosphericPressure.withValue(600);
assertEquals(first.hashCode(), second.hashCode());
first.setSeaLevelValue(200);
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void testToString() {
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(22.2);
assertNotNull(atmosphericPressure.toString());
assertNotEquals("", atmosphericPressure.toString());
}
}
@@ -0,0 +1,335 @@
/*
* 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.onecall;
import com.github.prominence.openweathermap.api.model.Clouds;
import com.github.prominence.openweathermap.api.model.Humidity;
import com.github.prominence.openweathermap.api.model.WeatherState;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.*;
public class CurrentUnitTest {
@Test
public void getForecastTime() {
final Current current = new Current();
final LocalDateTime now = LocalDateTime.now();
current.setForecastTime(now);
assertEquals(now, current.getForecastTime());
}
@Test
public void getSunriseTime() {
final Current current = new Current();
final LocalDateTime now = LocalDateTime.now();
current.setSunriseTime(now);
assertEquals(now, current.getSunriseTime());
}
@Test
public void getSunsetTime() {
final Current current = new Current();
final LocalDateTime now = LocalDateTime.now();
current.setSunsetTime(now);
assertEquals(now, current.getSunsetTime());
}
@Test
public void getWeatherState() {
final Current current = new Current();
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
current.setWeatherState(weatherState);
assertEquals(weatherState, current.getWeatherState());
}
@Test
public void getTemperature() {
final Current current = new Current();
final Temperature temperature = Temperature.withValue(10, "K");
current.setTemperature(temperature);
assertEquals(temperature, current.getTemperature());
}
@Test
public void getAtmosphericPressure() {
final Current current = new Current();
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(22.3);
current.setAtmosphericPressure(atmosphericPressure);
assertEquals(atmosphericPressure, current.getAtmosphericPressure());
}
@Test
public void getHumidity() {
final Current current = new Current();
final Humidity humidity = Humidity.withValue((byte) 10);
current.setHumidity(humidity);
assertEquals(humidity, current.getHumidity());
}
@Test
public void getWind() {
final Current current = new Current();
final Wind wind = Wind.withValue(13.2, "m/s");
current.setWind(wind);
assertEquals(wind, current.getWind());
}
@Test
public void getClouds() {
final Current current = new Current();
final Clouds clouds = Clouds.withValue((byte) 25);
current.setClouds(clouds);
assertEquals(clouds, current.getClouds());
}
@Test
public void getUvIndex() {
final Current current = new Current();
final double uvIndex = 22.4;
current.setUvIndex(uvIndex);
assertEquals(uvIndex, current.getUvIndex(), 0.00001);
current.setUvIndex(null);
assertNull(current.getUvIndex());
}
@Test
public void getIllegalUvIndexValue() {
final Current current = new Current();
assertThrows(IllegalArgumentException.class, () -> current.setUvIndex(-1.2));
}
@Test
public void getProbabilityOfPrecipitation() {
final Current current = new Current();
final double vim = 120;
current.setVisibilityInMetres(vim);
assertEquals(vim, current.getVisibilityInMetres(), 0.00001);
current.setVisibilityInMetres(null);
assertNull(current.getVisibilityInMetres());
}
@Test
public void getIllegalProbabilityOfPrecipitationValue_negative() {
final Current current = new Current();
assertThrows(IllegalArgumentException.class, () -> current.setVisibilityInMetres(-20.0));
}
@Test
public void getRain() {
final Current current = new Current();
final Rain rain = Rain.withOneHourLevelValue(20.2);
current.setRain(rain);
assertEquals(rain, current.getRain());
}
@Test
public void getSnow() {
final Current current = new Current();
final Snow snow = Snow.withOneHourLevelValue(25.0);
current.setSnow(snow);
assertEquals(snow, current.getSnow());
}
@Test
public void getEquals() {
final LocalDateTime now = LocalDateTime.now();
final Current first = new Current();
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
final Current second = new Current();
assertEquals(first, second);
first.setForecastTime(now);
assertNotEquals(first, second);
second.setForecastTime(now);
assertEquals(first, second);
first.setSunriseTime(now);
assertNotEquals(first, second);
second.setSunriseTime(now);
assertEquals(first, second);
first.setSunsetTime(now);
assertNotEquals(first, second);
second.setSunsetTime(now);
assertEquals(first, second);
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
first.setWeatherState(weatherState);
assertNotEquals(first, second);
second.setWeatherState(weatherState);
assertEquals(first, second);
final Temperature temperature = Temperature.withValue(10, "K");
first.setTemperature(temperature);
assertNotEquals(first, second);
second.setTemperature(temperature);
assertEquals(first, second);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(22.3);
first.setAtmosphericPressure(atmosphericPressure);
assertNotEquals(first, second);
second.setAtmosphericPressure(atmosphericPressure);
assertEquals(first, second);
final Humidity humidity = Humidity.withValue((byte) 10);
first.setHumidity(humidity);
assertNotEquals(first, second);
second.setHumidity(humidity);
assertEquals(first, second);
final Wind wind = Wind.withValue(13.2, "m/s");
first.setWind(wind);
assertNotEquals(first, second);
second.setWind(wind);
assertEquals(first, second);
final Clouds clouds = Clouds.withValue((byte) 25);
first.setClouds(clouds);
assertNotEquals(first, second);
second.setClouds(clouds);
assertEquals(first, second);
final double uvIndex = 22.4;
first.setUvIndex(uvIndex);
assertNotEquals(first, second);
second.setUvIndex(uvIndex);
assertEquals(first, second);
final double vim = 250;
first.setVisibilityInMetres(vim);
assertNotEquals(first, second);
second.setVisibilityInMetres(vim);
assertEquals(first, second);
final Rain rain = Rain.withOneHourLevelValue(20.2);
first.setRain(rain);
assertNotEquals(first, second);
second.setRain(rain);
assertEquals(first, second);
final Snow snow = Snow.withOneHourLevelValue(25.0);
first.setSnow(snow);
assertNotEquals(first, second);
second.setSnow(snow);
assertEquals(first, second);
}
@Test
public void getHashCode() {
final Current first = new Current();
final Current second = new Current();
assertEquals(first.hashCode(), second.hashCode());
first.setForecastTime(LocalDateTime.now());
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void getToString() {
final LocalDateTime now = LocalDateTime.now();
final Current current = new Current();
current.setForecastTime(now);
assertNotNull(current.toString());
assertNotEquals("", current.toString());
}
}
@@ -0,0 +1,85 @@
/*
* 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.onecall;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class RainUnitTest {
@Test
public void withInvalidValue_negative() {
assertThrows(IllegalArgumentException.class, () -> Rain.withOneHourLevelValue(-20.0));
}
@Test
public void getOneHourRainLevel() {
final Rain rain = Rain.withOneHourLevelValue(220.0);
assertEquals(220.0, rain.getOneHourLevel(), 0.00001);
}
@Test
public void getUnit() {
final Rain rain = Rain.withOneHourLevelValue(220.0);
assertNotNull(rain.getUnit());
assertNotEquals("", rain.getUnit());
}
@Test
public void testEquals() {
final Rain first = Rain.withOneHourLevelValue(600);
final Rain second = Rain.withOneHourLevelValue(600);
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
assertEquals(first, second);
first.setOneHourLevel(200);
assertNotEquals(first, second);
}
@Test
public void testHashCode() {
final Rain first = Rain.withOneHourLevelValue(600);
final Rain second = Rain.withOneHourLevelValue(600);
assertEquals(first.hashCode(), second.hashCode());
first.setOneHourLevel(200);
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void testToString() {
final Rain rain = Rain.withOneHourLevelValue(22.2);
assertNotNull(rain.toString());
assertNotEquals("", rain.toString());
}
}
@@ -0,0 +1,85 @@
/*
* 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.onecall;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class SnowUnitTest {
@Test
public void withInvalidValue_negative() {
assertThrows(IllegalArgumentException.class, () -> Snow.withOneHourLevelValue(-20.0));
}
@Test
public void getOneHourRainLevel() {
final Snow snow = Snow.withOneHourLevelValue(220.0);
assertEquals(220.0, snow.getOneHourLevel(), 0.00001);
}
@Test
public void getUnit() {
final Snow snow = Snow.withOneHourLevelValue(220.0);
assertNotNull(snow.getUnit());
assertNotEquals("", snow.getUnit());
}
@Test
public void testEquals() {
final Snow first = Snow.withOneHourLevelValue(600);
final Snow second = Snow.withOneHourLevelValue(600);
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
assertEquals(first, second);
first.setOneHourLevel(200);
assertNotEquals(first, second);
}
@Test
public void testHashCode() {
final Snow first = Snow.withOneHourLevelValue(600);
final Snow second = Snow.withOneHourLevelValue(600);
assertEquals(first.hashCode(), second.hashCode());
first.setOneHourLevel(200);
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void testToString() {
final Snow snow = Snow.withOneHourLevelValue(22.2);
assertNotNull(snow.toString());
assertNotEquals("", snow.toString());
}
}
@@ -0,0 +1,129 @@
/*
* 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.onecall;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class TemperatureUnitTest {
@Test
public void withInvalidValue_noUnit() {
assertThrows(IllegalArgumentException.class, () -> Temperature.withValue(-20, null));
}
@Test
public void getValue() {
final Temperature temperature = Temperature.withValue(20, "K");
assertEquals(20, temperature.getValue(), 0.00001);
}
@Test
public void getFeelsLike() {
final Temperature temperature = Temperature.withValue(20, "K");
temperature.setFeelsLike(18.0);
assertEquals(18.0, temperature.getFeelsLike(), 0.00001);
}
@Test
public void getDewPoint() {
final Temperature temperature = Temperature.withValue(20, "K");
temperature.setDewPoint(5.0);
assertEquals(5.0, temperature.getDewPoint(), 0.00001);
}
@Test
public void getUnit() {
final Temperature temperature = Temperature.withValue(20, "K");
assertEquals("K", temperature.getUnit());
}
@Test
public void testEquals() {
final Temperature first = Temperature.withValue(30, "L");
final Temperature second = Temperature.withValue(30, "K");
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
assertNotEquals(first, second);
first.setUnit("K");
assertEquals(first, second);
first.setFeelsLike(25.0);
assertNotEquals(first, second);
second.setFeelsLike(25.0);
assertEquals(first, second);
first.setDewPoint(10.0);
assertNotEquals(first, second);
second.setDewPoint(10.0);
assertEquals(first, second);
first.setValue(27.0);
assertNotEquals(first, second);
second.setValue(27.0);
assertEquals(first, second);
}
@Test
public void testHashCode() {
final Temperature first = Temperature.withValue(600, "K");
final Temperature second = Temperature.withValue(600, "K");
assertEquals(first.hashCode(), second.hashCode());
first.setFeelsLike(599d);
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void testToString() {
final Temperature temperature = Temperature.withValue(20, "K");
assertNotNull(temperature.toString());
assertNotEquals("", temperature.toString());
temperature.setFeelsLike(22.4);
assertNotNull(temperature.toString());
assertNotEquals("", temperature.toString());
}
}
@@ -0,0 +1,155 @@
/*
* 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.onecall;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class WindUnitTest {
@Test
public void withInvalidValue_noUnit() {
assertThrows(IllegalArgumentException.class, () -> Wind.withValue(20, null));
}
@Test
public void withInvalidValue_negative() {
assertThrows(IllegalArgumentException.class, () -> Wind.withValue(-20, "m/s"));
}
@Test
public void getSpeed() {
final Wind wind = Wind.withValue(20, "m/s");
assertEquals(20.0, wind.getSpeed(), 0.00001);
}
@Test
public void getGust() {
final Wind wind = Wind.withValue(20, "m/s");
wind.setGust(40);
assertEquals(40.0, wind.getGust(), 0.00001);
}
@Test
public void setGust_negative() {
final Wind wind = Wind.withValue(20, "m/s");
assertThrows(IllegalArgumentException.class, () -> wind.setGust(-20));
}
@Test
public void getDegrees() {
final Wind wind = Wind.withValue(20, "m/s");
wind.setDegrees(180);
assertEquals(180.0, wind.getDegrees(), 0.00001);
}
@Test
public void setDegrees_lessThanZero() {
final Wind wind = Wind.withValue(20, "m/s");
assertThrows(IllegalArgumentException.class, () -> wind.setDegrees(-20));
}
@Test
public void setDegrees_moreThan360() {
final Wind wind = Wind.withValue(20, "m/s");
assertThrows(IllegalArgumentException.class, () -> wind.setDegrees(420));
}
@Test
public void getUnit() {
final Wind wind = Wind.withValue(20, "m/s");
assertEquals("m/s", wind.getUnit());
}
@Test
public void testEquals() {
final Wind first = Wind.withValue(40, "m/s");
final Wind second = Wind.withValue(40, "m/s");
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
assertEquals(first, second);
first.setSpeed(20);
assertNotEquals(first, second);
second.setSpeed(20);
assertEquals(first, second);
first.setDegrees(10);
assertNotEquals(first, second);
second.setDegrees(10);
assertEquals(first, second);
first.setGust(30);
assertNotEquals(first, second);
second.setGust(30);
assertEquals(first, second);
second.setUnit("km/h");
assertNotEquals(first, second);
}
@Test
public void testHashCode() {
final Wind first = Wind.withValue(40, "m/s");
final Wind second = Wind.withValue(40, "m/s");
assertEquals(first.hashCode(), second.hashCode());
first.setGust(30);
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void testToString() {
final Wind wind = Wind.withValue(40, "m/s");
assertNotNull(wind.toString());
assertNotEquals("", wind.toString());
wind.setGust(20);
assertNotNull(wind.toString());
assertNotEquals("", wind.toString());
}
}
@@ -0,0 +1,148 @@
/*
* 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.onecall.current;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import static org.junit.jupiter.api.Assertions.*;
public class AlertUnitTest {
@Test
public void getSenderName() {
final Alert alert = new Alert();
alert.setSenderName("Sender");
assertEquals("Sender", alert.getSenderName());
}
@Test
public void getEventName() {
final Alert alert = new Alert();
alert.setEventName("Event");
assertEquals("Event", alert.getEventName());
}
@Test
public void getStartTime() {
final Alert alert = new Alert();
final LocalDateTime now = LocalDateTime.now();
alert.setStartTime(now);
assertEquals(now, alert.getStartTime());
}
@Test
public void getEndTime() {
final Alert alert = new Alert();
final LocalDateTime now = LocalDateTime.now();
alert.setEndTime(now);
assertEquals(now, alert.getEndTime());
}
@Test
public void getDescription() {
final Alert alert = new Alert();
alert.setDescription("Description");
assertEquals("Description", alert.getDescription());
}
@Test
public void getEquals() {
final Alert first = new Alert();
final Alert second = new Alert();
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
final String sender = "Sender";
final String event = "Event";
final String description = "Description";
final LocalDateTime now = LocalDateTime.now();
assertEquals(first, second);
first.setSenderName(sender);
assertNotEquals(first, second);
second.setSenderName(sender);
assertEquals(first, second);
first.setEventName(event);
assertNotEquals(first, second);
second.setEventName(event);
assertEquals(first, second);
first.setStartTime(now);
assertNotEquals(first, second);
second.setStartTime(now);
assertEquals(first, second);
first.setEndTime(now);
assertNotEquals(first, second);
second.setEndTime(now);
assertEquals(first, second);
first.setDescription(description);
assertNotEquals(first, second);
second.setDescription(description);
assertEquals(first, second);
}
@Test
public void getHashCode() {
final Alert event1 = new Alert("Sender", "Event1", LocalDateTime.now(), LocalDateTime.now().plus(2, ChronoUnit.HOURS), "Description1");
final Alert event2 = new Alert("Sender", "Event2", LocalDateTime.now(), LocalDateTime.now().plus(2, ChronoUnit.HOURS), "Description2");
assertEquals(event1.hashCode(), event1.hashCode());
assertNotEquals(event1.hashCode(), event2.hashCode());
}
@Test
public void getToString() {
final Alert alert = new Alert("Sender", "Event", LocalDateTime.now(), LocalDateTime.now().plus(2, ChronoUnit.HOURS), "Description");
assertNotNull(alert.toString());
assertNotEquals("", alert.toString());
}
}
@@ -0,0 +1,214 @@
/*
* 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.onecall.current;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.onecall.Current;
import org.junit.jupiter.api.Test;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
public class CurrentWeatherDataUnitTest {
@Test
public void getCoordinate() {
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
final Coordinate coordinate = Coordinate.of(11.2, 43.2);
currentWeatherData.setCoordinate(coordinate);
assertEquals(coordinate, currentWeatherData.getCoordinate());
}
@Test
public void getTimezone() {
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
final ZoneId timeZone = ZoneId.of("GMT");
currentWeatherData.setTimezone(timeZone);
assertEquals(timeZone, currentWeatherData.getTimezone());
}
@Test
public void getTimezoneOffset() {
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
final ZoneOffset offset = ZoneOffset.UTC;
currentWeatherData.setTimezoneOffset(offset);
assertEquals(offset, currentWeatherData.getTimezoneOffset());
}
@Test
public void getCurrent() {
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
final Current current = new Current();
currentWeatherData.setCurrent(current);
assertEquals(current, currentWeatherData.getCurrent());
}
@Test
public void getMinutelyList() {
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
final List<Minutely> minutelyList = new ArrayList<>();
currentWeatherData.setMinutelyList(minutelyList);
assertEquals(minutelyList, currentWeatherData.getMinutelyList());
}
@Test
public void getHourlyList() {
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
final List<Hourly> hourlyList = new ArrayList<>();
currentWeatherData.setHourlyList(hourlyList);
assertEquals(hourlyList, currentWeatherData.getHourlyList());
}
@Test
public void getDailyList() {
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
final List<Daily> dailyList = new ArrayList<>();
currentWeatherData.setDailyList(dailyList);
assertEquals(dailyList, currentWeatherData.getDailyList());
}
@Test
public void getAlerts() {
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
final List<Alert> alerts = new ArrayList<>();
currentWeatherData.setAlerts(alerts);
assertEquals(alerts, currentWeatherData.getAlerts());
}
@Test
public void getEquals() {
final CurrentWeatherData first = new CurrentWeatherData();
final CurrentWeatherData second = new CurrentWeatherData();
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
final Coordinate coordinate = Coordinate.of(11, 12);
final ZoneId timeZone = ZoneId.of("GMT");
final ZoneOffset offset = ZoneOffset.UTC;
final Current current = new Current();
final List<Minutely> minutelyList = new ArrayList<>();
final List<Hourly> hourlyList = new ArrayList<>();
final List<Daily> dailyList = new ArrayList<>();
final List<Alert> alerts = new ArrayList<>();
assertEquals(first, second);
first.setCoordinate(coordinate);
assertNotEquals(first, second);
second.setCoordinate(coordinate);
assertEquals(first, second);
first.setTimezone(timeZone);
assertNotEquals(first, second);
second.setTimezone(timeZone);
assertEquals(first, second);
first.setTimezoneOffset(offset);
assertNotEquals(first, second);
second.setTimezoneOffset(offset);
assertEquals(first, second);
first.setCurrent(current);
assertNotEquals(first, second);
second.setCurrent(current);
assertEquals(first, second);
first.setMinutelyList(minutelyList);
assertNotEquals(first, second);
second.setMinutelyList(minutelyList);
assertEquals(first, second);
first.setHourlyList(hourlyList);
assertNotEquals(first, second);
second.setHourlyList(hourlyList);
assertEquals(first, second);
first.setDailyList(dailyList);
assertNotEquals(first, second);
second.setDailyList(dailyList);
assertEquals(first, second);
first.setAlerts(alerts);
assertNotEquals(first, second);
second.setAlerts(alerts);
assertEquals(first, second);
}
@Test
public void getHashCode() {
final CurrentWeatherData first = new CurrentWeatherData();
final CurrentWeatherData second = new CurrentWeatherData();
assertEquals(first.hashCode(), second.hashCode());
first.setCoordinate(Coordinate.of(11, 42));
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void getToString() {
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
currentWeatherData.setCoordinate(Coordinate.of(32, 22));
assertNotNull(currentWeatherData.toString());
assertNotEquals("", currentWeatherData.toString());
}
}
@@ -0,0 +1,81 @@
/*
* 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.onecall.current;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class DailyRainUnitTest {
@Test
public void getValue() {
final DailyRain dailyRain = DailyRain.withValue(20);
assertEquals(20, dailyRain.getValue(), 0.00001);
}
@Test
public void getInvalidValue_negative() {
assertThrows(IllegalArgumentException.class, () -> DailyRain.withValue(-20));
}
@Test
public void getUnit() {
final DailyRain dailyRain = DailyRain.withValue(20);
assertNotNull(dailyRain.getUnit());
assertNotEquals("", dailyRain.getUnit());
}
@Test
public void getEquals() {
final DailyRain first = DailyRain.withValue(0);
final DailyRain second = DailyRain.withValue(0);
assertEquals(first, second);
first.setValue(20);
assertNotEquals(first, second);
}
@Test
public void getHashCode() {
final DailyRain first = DailyRain.withValue(0);
final DailyRain second = DailyRain.withValue(0);
assertEquals(first.hashCode(), second.hashCode());
first.setValue(20);
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void getToString() {
final DailyRain dailyRain = DailyRain.withValue(20);
assertNotNull(dailyRain.toString());
assertNotEquals("", dailyRain.toString());
}
}
@@ -0,0 +1,81 @@
/*
* 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.onecall.current;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class DailySnowUnitTest {
@Test
public void getValue() {
final DailySnow dailySnow = DailySnow.withValue(20);
assertEquals(20, dailySnow.getValue(), 0.00001);
}
@Test
public void getInvalidValue_negative() {
assertThrows(IllegalArgumentException.class, () -> DailySnow.withValue(-20));
}
@Test
public void getUnit() {
final DailySnow dailySnow = DailySnow.withValue(20);
assertNotNull(dailySnow.getUnit());
assertNotEquals("", dailySnow.getUnit());
}
@Test
public void getEquals() {
final DailySnow first = DailySnow.withValue(0);
final DailySnow second = DailySnow.withValue(0);
assertEquals(first, second);
first.setValue(20);
assertNotEquals(first, second);
}
@Test
public void getHashCode() {
final DailySnow first = DailySnow.withValue(0);
final DailySnow second = DailySnow.withValue(0);
assertEquals(first.hashCode(), second.hashCode());
first.setValue(20);
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void getToString() {
final DailySnow dailySnow = DailySnow.withValue(20);
assertNotNull(dailySnow.toString());
assertNotEquals("", dailySnow.toString());
}
}
@@ -0,0 +1,257 @@
/*
* 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.onecall.current;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class DailyTemperatureUnitTest {
@Test
public void getMorning() {
final DailyTemperature temperature = new DailyTemperature();
final double value = 20.0;
temperature.setMorning(value);
assertEquals(value, temperature.getMorning(), 0.00001);
}
@Test
public void getMorningFeelsLike() {
final DailyTemperature temperature = new DailyTemperature();
final double value = 20.0;
temperature.setMorningFeelsLike(value);
assertEquals(value, temperature.getMorningFeelsLike(), 0.00001);
}
@Test
public void getDay() {
final DailyTemperature temperature = new DailyTemperature();
final double value = 20.0;
temperature.setDay(value);
assertEquals(value, temperature.getDay(), 0.00001);
}
@Test
public void getDayFeelsLike() {
final DailyTemperature temperature = new DailyTemperature();
final double value = 20.0;
temperature.setDayFeelsLike(value);
assertEquals(value, temperature.getDayFeelsLike(), 0.00001);
}
@Test
public void getEve() {
final DailyTemperature temperature = new DailyTemperature();
final double value = 20.0;
temperature.setEve(value);
assertEquals(value, temperature.getEve(), 0.00001);
}
@Test
public void getEveFeelsLike() {
final DailyTemperature temperature = new DailyTemperature();
final double value = 20.0;
temperature.setEveFeelsLike(value);
assertEquals(value, temperature.getEveFeelsLike(), 0.00001);
}
@Test
public void getNight() {
final DailyTemperature temperature = new DailyTemperature();
final double value = 20.0;
temperature.setNight(value);
assertEquals(value, temperature.getNight(), 0.00001);
}
@Test
public void getNightFeelsLike() {
final DailyTemperature temperature = new DailyTemperature();
final double value = 20.0;
temperature.setNightFeelsLike(value);
assertEquals(value, temperature.getNightFeelsLike(), 0.00001);
}
@Test
public void getMin() {
final DailyTemperature temperature = new DailyTemperature();
final double value = 20.0;
temperature.setMin(value);
assertEquals(value, temperature.getMin(), 0.00001);
}
@Test
public void getMax() {
final DailyTemperature temperature = new DailyTemperature();
final double value = 20.0;
temperature.setMax(value);
assertEquals(value, temperature.getMax(), 0.00001);
}
@Test
public void getDewPoint() {
final DailyTemperature temperature = new DailyTemperature();
final double value = 20.0;
temperature.setDewPoint(value);
assertEquals(value, temperature.getDewPoint(), 0.00001);
}
@Test
public void getUnit() {
final DailyTemperature temperature = new DailyTemperature();
temperature.setUnit("T");
assertEquals("T", temperature.getUnit());
}
@Test
public void getEquals() {
final DailyTemperature first = new DailyTemperature();
final DailyTemperature second = new DailyTemperature();
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
assertEquals(first, second);
first.setMorning(1.0);
assertNotEquals(first, second);
second.setMorning(1.0);
assertEquals(first, second);
first.setMorningFeelsLike(2.0);
assertNotEquals(first, second);
second.setMorningFeelsLike(2.0);
assertEquals(first, second);
first.setDay(3.0);
assertNotEquals(first, second);
second.setDay(3.0);
assertEquals(first, second);
first.setDayFeelsLike(4.0);
assertNotEquals(first, second);
second.setDayFeelsLike(4.0);
assertEquals(first, second);
first.setEve(5.0);
assertNotEquals(first, second);
second.setEve(5.0);
assertEquals(first, second);
first.setEveFeelsLike(6.0);
assertNotEquals(first, second);
second.setEveFeelsLike(6.0);
assertEquals(first, second);
first.setNight(7.0);
assertNotEquals(first, second);
second.setNight(7.0);
assertEquals(first, second);
first.setNightFeelsLike(8.0);
assertNotEquals(first, second);
second.setNightFeelsLike(8.0);
assertEquals(first, second);
first.setDewPoint(9.0);
assertNotEquals(first, second);
second.setDewPoint(9.0);
assertEquals(first, second);
first.setMin(10.0);
assertNotEquals(first, second);
second.setMin(10.0);
assertEquals(first, second);
first.setMax(11.0);
assertNotEquals(first, second);
second.setMax(11.0);
assertEquals(first, second);
first.setUnit("K");
assertNotEquals(first, second);
second.setUnit("K");
assertEquals(first, second);
}
@Test
public void getHashCode() {
final DailyTemperature first = new DailyTemperature();
final DailyTemperature second = new DailyTemperature();
assertEquals(first.hashCode(), second.hashCode());
first.setUnit("K");
assertNotEquals(first.hashCode(), second.hashCode());
}
}
@@ -0,0 +1,395 @@
/*
* 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.onecall.current;
import com.github.prominence.openweathermap.api.model.Clouds;
import com.github.prominence.openweathermap.api.model.Humidity;
import com.github.prominence.openweathermap.api.model.WeatherState;
import com.github.prominence.openweathermap.api.model.onecall.AtmosphericPressure;
import com.github.prominence.openweathermap.api.model.onecall.Wind;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.*;
public class DailyUnitTest {
@Test
public void getForecastTime() {
final Daily daily = new Daily();
final LocalDateTime now = LocalDateTime.now();
daily.setForecastTime(now);
assertEquals(now, daily.getForecastTime());
}
@Test
public void getSunriseTime() {
final Daily daily = new Daily();
final LocalDateTime now = LocalDateTime.now();
daily.setSunriseTime(now);
assertEquals(now, daily.getSunriseTime());
}
@Test
public void getSunsetTime() {
final Daily daily = new Daily();
final LocalDateTime now = LocalDateTime.now();
daily.setSunsetTime(now);
assertEquals(now, daily.getSunsetTime());
}
@Test
public void getWeatherState() {
final Daily daily = new Daily();
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
daily.setWeatherState(weatherState);
assertEquals(weatherState, daily.getWeatherState());
}
@Test
public void getTemperature() {
final Daily daily = new Daily();
final DailyTemperature dailyTemperature = new DailyTemperature();
dailyTemperature.setDay(10.0);
dailyTemperature.setEveFeelsLike(44.2);
daily.setTemperature(dailyTemperature);
assertEquals(dailyTemperature, daily.getTemperature());
}
@Test
public void getAtmosphericPressure() {
final Daily daily = new Daily();
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(22.3);
daily.setAtmosphericPressure(atmosphericPressure);
assertEquals(atmosphericPressure, daily.getAtmosphericPressure());
}
@Test
public void getHumidity() {
final Daily daily = new Daily();
final Humidity humidity = Humidity.withValue((byte) 10);
daily.setHumidity(humidity);
assertEquals(humidity, daily.getHumidity());
}
@Test
public void getWind() {
final Daily daily = new Daily();
final Wind wind = Wind.withValue(13.2, "m/s");
daily.setWind(wind);
assertEquals(wind, daily.getWind());
}
@Test
public void getClouds() {
final Daily daily = new Daily();
final Clouds clouds = Clouds.withValue((byte) 25);
daily.setClouds(clouds);
assertEquals(clouds, daily.getClouds());
}
@Test
public void getUvIndex() {
final Daily daily = new Daily();
final double uvIndex = 22.4;
daily.setUvIndex(uvIndex);
assertEquals(uvIndex, daily.getUvIndex(), 0.00001);
daily.setUvIndex(null);
assertNull(daily.getUvIndex());
}
@Test
public void getIllegalUvIndexValue() {
final Daily daily = new Daily();
assertThrows(IllegalArgumentException.class, () -> daily.setUvIndex(-1.2));
}
@Test
public void getProbabilityOfPrecipitation() {
final Daily daily = new Daily();
final double pop = 70.5;
daily.setProbabilityOfPrecipitation(pop);
assertEquals(pop, daily.getProbabilityOfPrecipitation(), 0.00001);
daily.setProbabilityOfPrecipitation(null);
assertNull(daily.getProbabilityOfPrecipitation());
}
@Test
public void getIllegalProbabilityOfPrecipitationValue_negative() {
final Daily daily = new Daily();
assertThrows(IllegalArgumentException.class, () -> daily.setProbabilityOfPrecipitation(-20.0));
}
@Test
public void getIllegalProbabilityOfPrecipitationValue_tooBig() {
final Daily daily = new Daily();
assertThrows(IllegalArgumentException.class, () -> daily.setProbabilityOfPrecipitation(120.0));
}
@Test
public void getRain() {
final Daily daily = new Daily();
final DailyRain rain = DailyRain.withValue(20.2);
daily.setRain(rain);
assertEquals(rain, daily.getRain());
}
@Test
public void getSnow() {
final Daily daily = new Daily();
final DailySnow snow = DailySnow.withValue(25.0);
daily.setSnow(snow);
assertEquals(snow, daily.getSnow());
}
@Test
public void getEquals() {
final LocalDateTime now = LocalDateTime.now();
final Daily first = new Daily();
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
final Daily second = new Daily();
assertEquals(first, second);
first.setForecastTime(now);
assertNotEquals(first, second);
second.setForecastTime(now);
assertEquals(first, second);
first.setSunriseTime(now);
assertNotEquals(first, second);
second.setSunriseTime(now);
assertEquals(first, second);
first.setSunsetTime(now);
assertNotEquals(first, second);
second.setSunsetTime(now);
assertEquals(first, second);
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
first.setWeatherState(weatherState);
assertNotEquals(first, second);
second.setWeatherState(weatherState);
assertEquals(first, second);
final DailyTemperature dailyTemperature = new DailyTemperature();
first.setTemperature(dailyTemperature);
assertNotEquals(first, second);
second.setTemperature(dailyTemperature);
assertEquals(first, second);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(22.3);
first.setAtmosphericPressure(atmosphericPressure);
assertNotEquals(first, second);
second.setAtmosphericPressure(atmosphericPressure);
assertEquals(first, second);
final Humidity humidity = Humidity.withValue((byte) 10);
first.setHumidity(humidity);
assertNotEquals(first, second);
second.setHumidity(humidity);
assertEquals(first, second);
final Wind wind = Wind.withValue(13.2, "m/s");
first.setWind(wind);
assertNotEquals(first, second);
second.setWind(wind);
assertEquals(first, second);
final Clouds clouds = Clouds.withValue((byte) 25);
first.setClouds(clouds);
assertNotEquals(first, second);
second.setClouds(clouds);
assertEquals(first, second);
final double uvIndex = 22.4;
first.setUvIndex(uvIndex);
assertNotEquals(first, second);
second.setUvIndex(uvIndex);
assertEquals(first, second);
final double pop = 70.5;
first.setProbabilityOfPrecipitation(pop);
assertNotEquals(first, second);
second.setProbabilityOfPrecipitation(pop);
assertEquals(first, second);
final DailyRain rain = DailyRain.withValue(20.2);
first.setRain(rain);
assertNotEquals(first, second);
second.setRain(rain);
assertEquals(first, second);
final DailySnow snow = DailySnow.withValue(25.0);
first.setSnow(snow);
assertNotEquals(first, second);
second.setSnow(snow);
assertEquals(first, second);
}
@Test
public void getHashCode() {
final Daily first = new Daily();
final Daily second = new Daily();
assertEquals(first.hashCode(), second.hashCode());
first.setForecastTime(LocalDateTime.now());
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void getToString() {
final LocalDateTime now = LocalDateTime.now();
final Daily daily = new Daily();
daily.setForecastTime(now);
assertNotNull(daily.toString());
assertNotEquals("", daily.toString());
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
daily.setWeatherState(weatherState);
assertNotNull(daily.toString());
assertNotEquals("", daily.toString());
final DailyTemperature dailyTemperature = new DailyTemperature();
daily.setTemperature(dailyTemperature);
assertNotNull(daily.toString());
assertNotEquals("", daily.toString());
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(22.3);
daily.setAtmosphericPressure(atmosphericPressure);
assertNotNull(daily.toString());
assertNotEquals("", daily.toString());
final Wind wind = Wind.withValue(13.2, "m/s");
daily.setWind(wind);
assertNotNull(daily.toString());
assertNotEquals("", daily.toString());
final Clouds clouds = Clouds.withValue((byte) 25);
daily.setClouds(clouds);
assertNotNull(daily.toString());
assertNotEquals("", daily.toString());
final DailyRain rain = DailyRain.withValue(20.2);
daily.setRain(rain);
assertNotNull(daily.toString());
assertNotEquals("", daily.toString());
final DailySnow snow = DailySnow.withValue(25.0);
daily.setSnow(snow);
assertNotNull(daily.toString());
assertNotEquals("", daily.toString());
}
}
@@ -0,0 +1,285 @@
/*
* 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.onecall.current;
import com.github.prominence.openweathermap.api.model.Clouds;
import com.github.prominence.openweathermap.api.model.Humidity;
import com.github.prominence.openweathermap.api.model.WeatherState;
import com.github.prominence.openweathermap.api.model.onecall.*;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.*;
public class HourlyUnitTest {
@Test
public void getForecastTime() {
final Hourly hourly = new Hourly();
final LocalDateTime now = LocalDateTime.now();
hourly.setForecastTime(now);
assertEquals(now, hourly.getForecastTime());
}
@Test
public void getWeatherState() {
final Hourly hourly = new Hourly();
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
hourly.setWeatherState(weatherState);
assertEquals(weatherState, hourly.getWeatherState());
}
@Test
public void getTemperature() {
final Hourly hourly = new Hourly();
final Temperature temperature = Temperature.withValue(10, "K");
hourly.setTemperature(temperature);
assertEquals(temperature, hourly.getTemperature());
}
@Test
public void getAtmosphericPressure() {
final Hourly hourly = new Hourly();
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(100);
hourly.setAtmosphericPressure(atmosphericPressure);
assertEquals(atmosphericPressure, hourly.getAtmosphericPressure());
}
@Test
public void getHumidity() {
final Hourly hourly = new Hourly();
final Humidity humidity = Humidity.withValue((byte) 20);
hourly.setHumidity(humidity);
assertEquals(humidity, hourly.getHumidity());
}
@Test
public void getUvIndex() {
final Hourly hourly = new Hourly();
final double uvIndex = 20.0;
hourly.setUvIndex(uvIndex);
assertEquals(uvIndex, hourly.getUvIndex(), 0.00001);
}
@Test
public void getClouds() {
final Hourly hourly = new Hourly();
final Clouds clouds = Clouds.withValue((byte) 60);
hourly.setClouds(clouds);
assertEquals(clouds, hourly.getClouds());
}
@Test
public void getVisibilityInMetres() {
final Hourly hourly = new Hourly();
final double vim = 40.0;
hourly.setVisibilityInMetres(vim);
assertEquals(vim, hourly.getVisibilityInMetres(), 0.00001);
}
@Test
public void getWind() {
final Hourly hourly = new Hourly();
final Wind wind = Wind.withValue(200, "m/s");
hourly.setWind(wind);
assertEquals(wind, hourly.getWind());
}
@Test
public void getProbabilityOfPrecipitation() {
final Hourly hourly = new Hourly();
final double pop = 42.0;
hourly.setProbabilityOfPrecipitation(pop);
assertEquals(pop, hourly.getProbabilityOfPrecipitation(), 0.00001);
}
@Test
public void getRain() {
final Hourly hourly = new Hourly();
final Rain rain = Rain.withOneHourLevelValue(100);
hourly.setRain(rain);
assertEquals(rain, hourly.getRain());
}
@Test
public void getSnow() {
final Hourly hourly = new Hourly();
final Snow snow = Snow.withOneHourLevelValue(29);
hourly.setSnow(snow);
assertEquals(snow, hourly.getSnow());
}
@Test
public void testEquals() {
final Hourly first = new Hourly();
final Hourly second = new Hourly();
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
final LocalDateTime forecastTime = LocalDateTime.now();
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
final Temperature temperature = Temperature.withValue(10, "K");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(200);
final Humidity humidity = Humidity.withValue((byte) 13);
final double uvIndex = 10.0;
final Clouds clouds = Clouds.withValue((byte) 20);
final double vim = 20;
final Wind wind = Wind.withValue(20, "m/s");
final double pop = 30;
final Rain rain = Rain.withOneHourLevelValue(40);
final Snow snow = Snow.withOneHourLevelValue(11);
assertEquals(first, second);
first.setForecastTime(forecastTime);
assertNotEquals(first, second);
second.setForecastTime(forecastTime);
assertEquals(first, second);
first.setWeatherState(weatherState);
assertNotEquals(first, second);
second.setWeatherState(weatherState);
assertEquals(first, second);
first.setTemperature(temperature);
assertNotEquals(first, second);
second.setTemperature(temperature);
assertEquals(first, second);
first.setAtmosphericPressure(atmosphericPressure);
assertNotEquals(first, second);
second.setAtmosphericPressure(atmosphericPressure);
assertEquals(first, second);
first.setHumidity(humidity);
assertNotEquals(first, second);
second.setHumidity(humidity);
assertEquals(first, second);
first.setUvIndex(uvIndex);
assertNotEquals(first, second);
second.setUvIndex(uvIndex);
assertEquals(first, second);
first.setClouds(clouds);
assertNotEquals(first, second);
second.setClouds(clouds);
assertEquals(first, second);
first.setVisibilityInMetres(vim);
assertNotEquals(first, second);
second.setVisibilityInMetres(vim);
assertEquals(first, second);
first.setWind(wind);
assertNotEquals(first, second);
second.setWind(wind);
assertEquals(first, second);
first.setProbabilityOfPrecipitation(pop);
assertNotEquals(first, second);
second.setProbabilityOfPrecipitation(pop);
assertEquals(first, second);
first.setRain(rain);
assertNotEquals(first, second);
second.setRain(rain);
assertEquals(first, second);
first.setSnow(snow);
assertNotEquals(first, second);
second.setSnow(snow);
assertEquals(first, second);
}
@Test
public void testHashCode() {
final Hourly first = new Hourly();
final Hourly second = new Hourly();
assertEquals(first.hashCode(), second.hashCode());
first.setForecastTime(LocalDateTime.now());
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void testToString() {
final Hourly hourly = new Hourly();
hourly.setForecastTime(LocalDateTime.now());
assertNotNull(hourly.toString());
assertNotEquals("", hourly.toString());
}
}
@@ -0,0 +1,86 @@
/*
* 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.onecall.current;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.*;
public class MinutelyUnitTest {
@Test
public void withValue() {
final LocalDateTime now = LocalDateTime.now();
final Minutely minutely = Minutely.withValue(now, 10.0);
assertEquals(now, minutely.getForecastTime());
assertEquals(10.0, minutely.getPrecipitationVolume(), 0.00001);
}
@Test
public void withInvalidValueValue_negative() {
assertThrows(IllegalArgumentException.class, () -> Minutely.withValue(LocalDateTime.now(), -10.0));
}
@Test
public void testEquals() {
final LocalDateTime now = LocalDateTime.now();
final Minutely first = Minutely.withValue(now, 10.0);
final Minutely firstCopy = Minutely.withValue(now, 10.0);
final Minutely second = Minutely.withValue(now, 11.0);
final Minutely secondCopy = Minutely.withValue(now.plusMinutes(11), 11.0);
final Minutely third = Minutely.withValue(now.plusMinutes(22), 44.9);
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
assertEquals(first, firstCopy);
assertNotEquals(first, second);
assertNotEquals(second, secondCopy);
assertNotEquals(second, third);
}
@Test
public void testHashCode() {
final LocalDateTime now = LocalDateTime.now();
final Minutely first = Minutely.withValue(now, 10.0);
final Minutely firstCopy = Minutely.withValue(now, 10.0);
final Minutely second = Minutely.withValue(now.plusMinutes(2), 11.0);
assertEquals(first.hashCode(), first.hashCode());
assertEquals(first.hashCode(), firstCopy.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void testToString() {
final Minutely minutely = Minutely.withValue(LocalDateTime.now(), 10.0);
assertNotNull(minutely.toString());
assertNotEquals("", minutely.toString());
}
}
@@ -0,0 +1,159 @@
/*
* 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.onecall.historical;
import com.github.prominence.openweathermap.api.model.Coordinate;
import org.junit.jupiter.api.Test;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
public class HistoricalWeatherDataUnitTest {
@Test
public void getCoordinate() {
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
final Coordinate coordinate = Coordinate.of(11.2, 43.2);
historicalWeatherData.setCoordinate(coordinate);
assertEquals(coordinate, historicalWeatherData.getCoordinate());
}
@Test
public void getTimezone() {
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
final ZoneId timeZone = ZoneId.of("GMT");
historicalWeatherData.setTimezone(timeZone);
assertEquals(timeZone, historicalWeatherData.getTimezone());
}
@Test
public void getTimezoneOffset() {
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
final ZoneOffset offset = ZoneOffset.UTC;
historicalWeatherData.setTimezoneOffset(offset);
assertEquals(offset, historicalWeatherData.getTimezoneOffset());
}
@Test
public void getHistoricalWeather() {
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
final HistoricalWeather historicalWeather = new HistoricalWeather();
historicalWeatherData.setHistoricalWeather(historicalWeather);
assertEquals(historicalWeather, historicalWeatherData.getHistoricalWeather());
}
@Test
public void getHourlyList() {
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
final List<HourlyHistorical> hourlyList = new ArrayList<>();
historicalWeatherData.setHourlyList(hourlyList);
assertEquals(hourlyList, historicalWeatherData.getHourlyList());
}
@Test
public void getEquals() {
final HistoricalWeatherData first = new HistoricalWeatherData();
final HistoricalWeatherData second = new HistoricalWeatherData();
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
final Coordinate coordinate = Coordinate.of(11, 12);
final ZoneId timeZone = ZoneId.of("GMT");
final ZoneOffset offset = ZoneOffset.UTC;
final HistoricalWeather historicalWeather = new HistoricalWeather();
final List<HourlyHistorical> hourlyList = new ArrayList<>();
assertEquals(first, second);
first.setCoordinate(coordinate);
assertNotEquals(first, second);
second.setCoordinate(coordinate);
assertEquals(first, second);
first.setTimezone(timeZone);
assertNotEquals(first, second);
second.setTimezone(timeZone);
assertEquals(first, second);
first.setTimezoneOffset(offset);
assertNotEquals(first, second);
second.setTimezoneOffset(offset);
assertEquals(first, second);
first.setHistoricalWeather(historicalWeather);
assertNotEquals(first, second);
second.setHistoricalWeather(historicalWeather);
assertEquals(first, second);
first.setHourlyList(hourlyList);
assertNotEquals(first, second);
second.setHourlyList(hourlyList);
assertEquals(first, second);
}
@Test
public void getHashCode() {
final HistoricalWeatherData first = new HistoricalWeatherData();
final HistoricalWeatherData second = new HistoricalWeatherData();
assertEquals(first.hashCode(), second.hashCode());
first.setCoordinate(Coordinate.of(11, 42));
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void getToString() {
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
historicalWeatherData.setCoordinate(Coordinate.of(32, 22));
assertNotNull(historicalWeatherData.toString());
assertNotEquals("", historicalWeatherData.toString());
}
}
@@ -0,0 +1,336 @@
/*
* 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.onecall.historical;
import com.github.prominence.openweathermap.api.model.Clouds;
import com.github.prominence.openweathermap.api.model.Humidity;
import com.github.prominence.openweathermap.api.model.WeatherState;
import com.github.prominence.openweathermap.api.model.onecall.*;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.*;
public class HistoricalWeatherUnitTest {
@Test
public void getForecastTime() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final LocalDateTime now = LocalDateTime.now();
historicalWeather.setForecastTime(now);
assertEquals(now, historicalWeather.getForecastTime());
}
@Test
public void getSunriseTime() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final LocalDateTime now = LocalDateTime.now();
historicalWeather.setSunriseTime(now);
assertEquals(now, historicalWeather.getSunriseTime());
}
@Test
public void getSunsetTime() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final LocalDateTime now = LocalDateTime.now();
historicalWeather.setSunsetTime(now);
assertEquals(now, historicalWeather.getSunsetTime());
}
@Test
public void getWeatherState() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
historicalWeather.setWeatherState(weatherState);
assertEquals(weatherState, historicalWeather.getWeatherState());
}
@Test
public void getTemperature() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final Temperature temperature = Temperature.withValue(10, "K");
historicalWeather.setTemperature(temperature);
assertEquals(temperature, historicalWeather.getTemperature());
}
@Test
public void getAtmosphericPressure() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(22.3);
historicalWeather.setAtmosphericPressure(atmosphericPressure);
assertEquals(atmosphericPressure, historicalWeather.getAtmosphericPressure());
}
@Test
public void getHumidity() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final Humidity humidity = Humidity.withValue((byte) 10);
historicalWeather.setHumidity(humidity);
assertEquals(humidity, historicalWeather.getHumidity());
}
@Test
public void getWind() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final Wind wind = Wind.withValue(13.2, "m/s");
historicalWeather.setWind(wind);
assertEquals(wind, historicalWeather.getWind());
}
@Test
public void getClouds() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final Clouds clouds = Clouds.withValue((byte) 25);
historicalWeather.setClouds(clouds);
assertEquals(clouds, historicalWeather.getClouds());
}
@Test
public void getUvIndex() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final double uvIndex = 22.4;
historicalWeather.setUvIndex(uvIndex);
assertEquals(uvIndex, historicalWeather.getUvIndex(), 0.00001);
historicalWeather.setUvIndex(null);
assertNull(historicalWeather.getUvIndex());
}
@Test
public void getIllegalUvIndexValue() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
assertThrows(IllegalArgumentException.class, () -> historicalWeather.setUvIndex(-1.2));
}
@Test
public void getProbabilityOfPrecipitation() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final double vim = 120;
historicalWeather.setVisibilityInMetres(vim);
assertEquals(vim, historicalWeather.getVisibilityInMetres(), 0.00001);
historicalWeather.setVisibilityInMetres(null);
assertNull(historicalWeather.getVisibilityInMetres());
}
@Test
public void getIllegalProbabilityOfPrecipitationValue_negative() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
assertThrows(IllegalArgumentException.class, () -> historicalWeather.setVisibilityInMetres(-20.0));
}
@Test
public void getRain() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final Rain rain = Rain.withOneHourLevelValue(20.2);
historicalWeather.setRain(rain);
assertEquals(rain, historicalWeather.getRain());
}
@Test
public void getSnow() {
final HistoricalWeather historicalWeather = new HistoricalWeather();
final Snow snow = Snow.withOneHourLevelValue(25.0);
historicalWeather.setSnow(snow);
assertEquals(snow, historicalWeather.getSnow());
}
@Test
public void getEquals() {
final LocalDateTime now = LocalDateTime.now();
final HistoricalWeather first = new HistoricalWeather();
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
final HistoricalWeather second = new HistoricalWeather();
assertEquals(first, second);
first.setForecastTime(now);
assertNotEquals(first, second);
second.setForecastTime(now);
assertEquals(first, second);
first.setSunriseTime(now);
assertNotEquals(first, second);
second.setSunriseTime(now);
assertEquals(first, second);
first.setSunsetTime(now);
assertNotEquals(first, second);
second.setSunsetTime(now);
assertEquals(first, second);
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
first.setWeatherState(weatherState);
assertNotEquals(first, second);
second.setWeatherState(weatherState);
assertEquals(first, second);
final Temperature temperature = Temperature.withValue(10, "K");
first.setTemperature(temperature);
assertNotEquals(first, second);
second.setTemperature(temperature);
assertEquals(first, second);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(22.3);
first.setAtmosphericPressure(atmosphericPressure);
assertNotEquals(first, second);
second.setAtmosphericPressure(atmosphericPressure);
assertEquals(first, second);
final Humidity humidity = Humidity.withValue((byte) 10);
first.setHumidity(humidity);
assertNotEquals(first, second);
second.setHumidity(humidity);
assertEquals(first, second);
final Wind wind = Wind.withValue(13.2, "m/s");
first.setWind(wind);
assertNotEquals(first, second);
second.setWind(wind);
assertEquals(first, second);
final Clouds clouds = Clouds.withValue((byte) 25);
first.setClouds(clouds);
assertNotEquals(first, second);
second.setClouds(clouds);
assertEquals(first, second);
final double uvIndex = 22.4;
first.setUvIndex(uvIndex);
assertNotEquals(first, second);
second.setUvIndex(uvIndex);
assertEquals(first, second);
final double vim = 250;
first.setVisibilityInMetres(vim);
assertNotEquals(first, second);
second.setVisibilityInMetres(vim);
assertEquals(first, second);
final Rain rain = Rain.withOneHourLevelValue(20.2);
first.setRain(rain);
assertNotEquals(first, second);
second.setRain(rain);
assertEquals(first, second);
final Snow snow = Snow.withOneHourLevelValue(25.0);
first.setSnow(snow);
assertNotEquals(first, second);
second.setSnow(snow);
assertEquals(first, second);
}
@Test
public void getHashCode() {
final HistoricalWeather first = new HistoricalWeather();
final HistoricalWeather second = new HistoricalWeather();
assertEquals(first.hashCode(), second.hashCode());
first.setForecastTime(LocalDateTime.now());
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void getToString() {
final LocalDateTime now = LocalDateTime.now();
final HistoricalWeather historicalWeather = new HistoricalWeather();
historicalWeather.setForecastTime(now);
assertNotNull(historicalWeather.toString());
assertNotEquals("", historicalWeather.toString());
}
}
@@ -0,0 +1,249 @@
/*
* 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.onecall.historical;
import com.github.prominence.openweathermap.api.model.Clouds;
import com.github.prominence.openweathermap.api.model.Humidity;
import com.github.prominence.openweathermap.api.model.WeatherState;
import com.github.prominence.openweathermap.api.model.onecall.*;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.*;
public class HourlyHistoricalUnitTest {
@Test
public void getForecastTime() {
final HourlyHistorical hourlyHistorical = new HourlyHistorical();
final LocalDateTime now = LocalDateTime.now();
hourlyHistorical.setForecastTime(now);
assertEquals(now, hourlyHistorical.getForecastTime());
}
@Test
public void getWeatherState() {
final HourlyHistorical hourlyHistorical = new HourlyHistorical();
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
hourlyHistorical.setWeatherState(weatherState);
assertEquals(weatherState, hourlyHistorical.getWeatherState());
}
@Test
public void getTemperature() {
final HourlyHistorical hourlyHistorical = new HourlyHistorical();
final Temperature temperature = Temperature.withValue(10, "K");
hourlyHistorical.setTemperature(temperature);
assertEquals(temperature, hourlyHistorical.getTemperature());
}
@Test
public void getAtmosphericPressure() {
final HourlyHistorical hourlyHistorical = new HourlyHistorical();
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(100);
hourlyHistorical.setAtmosphericPressure(atmosphericPressure);
assertEquals(atmosphericPressure, hourlyHistorical.getAtmosphericPressure());
}
@Test
public void getHumidity() {
final HourlyHistorical hourlyHistorical = new HourlyHistorical();
final Humidity humidity = Humidity.withValue((byte) 20);
hourlyHistorical.setHumidity(humidity);
assertEquals(humidity, hourlyHistorical.getHumidity());
}
@Test
public void getClouds() {
final HourlyHistorical hourlyHistorical = new HourlyHistorical();
final Clouds clouds = Clouds.withValue((byte) 60);
hourlyHistorical.setClouds(clouds);
assertEquals(clouds, hourlyHistorical.getClouds());
}
@Test
public void getVisibilityInMetres() {
final HourlyHistorical hourlyHistorical = new HourlyHistorical();
final double vim = 40.0;
hourlyHistorical.setVisibilityInMetres(vim);
assertEquals(vim, hourlyHistorical.getVisibilityInMetres(), 0.00001);
}
@Test
public void getWind() {
final HourlyHistorical hourlyHistorical = new HourlyHistorical();
final Wind wind = Wind.withValue(200, "m/s");
hourlyHistorical.setWind(wind);
assertEquals(wind, hourlyHistorical.getWind());
}
@Test
public void getRain() {
final HourlyHistorical hourlyHistorical = new HourlyHistorical();
final Rain rain = Rain.withOneHourLevelValue(100);
hourlyHistorical.setRain(rain);
assertEquals(rain, hourlyHistorical.getRain());
}
@Test
public void getSnow() {
final HourlyHistorical hourlyHistorical = new HourlyHistorical();
final Snow snow = Snow.withOneHourLevelValue(29);
hourlyHistorical.setSnow(snow);
assertEquals(snow, hourlyHistorical.getSnow());
}
@Test
public void testEquals() {
final HourlyHistorical first = new HourlyHistorical();
final HourlyHistorical second = new HourlyHistorical();
assertEquals(first, first);
assertNotEquals(first, null);
assertNotEquals(first, new Object());
final LocalDateTime forecastTime = LocalDateTime.now();
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
final Temperature temperature = Temperature.withValue(10, "K");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(200);
final Humidity humidity = Humidity.withValue((byte) 13);
final Clouds clouds = Clouds.withValue((byte) 20);
final double vim = 20;
final Wind wind = Wind.withValue(20, "m/s");
final Rain rain = Rain.withOneHourLevelValue(40);
final Snow snow = Snow.withOneHourLevelValue(11);
assertEquals(first, second);
first.setForecastTime(forecastTime);
assertNotEquals(first, second);
second.setForecastTime(forecastTime);
assertEquals(first, second);
first.setWeatherState(weatherState);
assertNotEquals(first, second);
second.setWeatherState(weatherState);
assertEquals(first, second);
first.setTemperature(temperature);
assertNotEquals(first, second);
second.setTemperature(temperature);
assertEquals(first, second);
first.setAtmosphericPressure(atmosphericPressure);
assertNotEquals(first, second);
second.setAtmosphericPressure(atmosphericPressure);
assertEquals(first, second);
first.setHumidity(humidity);
assertNotEquals(first, second);
second.setHumidity(humidity);
assertEquals(first, second);
first.setClouds(clouds);
assertNotEquals(first, second);
second.setClouds(clouds);
assertEquals(first, second);
first.setVisibilityInMetres(vim);
assertNotEquals(first, second);
second.setVisibilityInMetres(vim);
assertEquals(first, second);
first.setWind(wind);
assertNotEquals(first, second);
second.setWind(wind);
assertEquals(first, second);
first.setRain(rain);
assertNotEquals(first, second);
second.setRain(rain);
assertEquals(first, second);
first.setSnow(snow);
assertNotEquals(first, second);
second.setSnow(snow);
assertEquals(first, second);
}
@Test
public void testHashCode() {
final HourlyHistorical first = new HourlyHistorical();
final HourlyHistorical second = new HourlyHistorical();
assertEquals(first.hashCode(), second.hashCode());
first.setForecastTime(LocalDateTime.now());
assertNotEquals(first.hashCode(), second.hashCode());
}
@Test
public void testToString() {
final HourlyHistorical hourlyHistorical = new HourlyHistorical();
hourlyHistorical.setForecastTime(LocalDateTime.now());
assertNotNull(hourlyHistorical.toString());
assertNotEquals("", hourlyHistorical.toString());
}
}
@@ -23,21 +23,22 @@
package com.github.prominence.openweathermap.api.model.weather;
import com.github.prominence.openweathermap.api.model.Coordinate;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import static org.junit.jupiter.api.Assertions.*;
public class LocationUnitTest {
@Test
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
Location.withValues(33, "test");
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateObjectWithoutName_thenThrowAnException() {
Location.withValues(33, null);
assertThrows(IllegalArgumentException.class, () -> Location.withValues(33, null));
}
@Test
@@ -45,7 +46,7 @@ public class LocationUnitTest {
final Location location = Location.withValues(33, "test");
location.setId(55);
Assert.assertEquals(55, location.getId());
assertEquals(55, location.getId());
}
@Test
@@ -53,7 +54,7 @@ public class LocationUnitTest {
final Location location = Location.withValues(33, "test");
location.setName("city");
Assert.assertEquals("city", location.getName());
assertEquals("city", location.getName());
}
@Test
@@ -61,25 +62,25 @@ public class LocationUnitTest {
final Location location = Location.withValues(33, "test");
location.setCountryCode("by");
Assert.assertEquals("by", location.getCountryCode());
assertEquals("by", location.getCountryCode());
}
@Test
public void whenSetSunrise_thenValueIsSet() {
final Location location = Location.withValues(33, "test");
final LocalDateTime now = LocalDateTime.now();
location.setSunrise(now);
location.setSunriseTime(now);
Assert.assertEquals(now, location.getSunrise());
assertEquals(now, location.getSunriseTime());
}
@Test
public void whenSetSunset_thenValueIsSet() {
final Location location = Location.withValues(33, "test");
final LocalDateTime now = LocalDateTime.now();
location.setSunset(now);
location.setSunsetTime(now);
Assert.assertEquals(now, location.getSunset());
assertEquals(now, location.getSunsetTime());
}
@Test
@@ -88,32 +89,32 @@ public class LocationUnitTest {
final ZoneOffset offset = ZoneOffset.UTC;
location.setZoneOffset(offset);
Assert.assertEquals(offset, location.getZoneOffset());
assertEquals(offset, location.getZoneOffset());
}
@Test
public void whenSetCoordinate_thenValueIsSet() {
final Location location = Location.withValues(33, "test");
final Coordinate coordinate = Coordinate.withValues(33.2, 64.2);
final Coordinate coordinate = Coordinate.of(33.2, 64.2);
location.setCoordinate(coordinate);
Assert.assertEquals(coordinate, location.getCoordinate());
assertEquals(coordinate, location.getCoordinate());
}
@Test
public void whenCallToString_thenAllIsFine() {
final Location location = Location.withValues(44, "test");
Assert.assertNotEquals("", location.toString());
assertNotEquals("", location.toString());
location.setCoordinate(Coordinate.withValues(33.2, 56.3));
location.setCoordinate(Coordinate.of(33.2, 56.3));
Assert.assertNotEquals("", location.toString());
assertNotEquals("", location.toString());
location.setCountryCode("TN");
Assert.assertNotEquals("", location.toString());
Assert.assertNotNull(location.toString());
assertNotEquals("", location.toString());
assertNotNull(location.toString());
}
@Test
@@ -121,11 +122,11 @@ public class LocationUnitTest {
final Location one = Location.withValues(44, "test");
final Location two = Location.withValues(44, "test");
Assert.assertEquals(one.hashCode(), two.hashCode());
assertEquals(one.hashCode(), two.hashCode());
two.setName("112");
Assert.assertNotEquals(one.hashCode(), two.hashCode());
assertNotEquals(one.hashCode(), two.hashCode());
}
@Test
@@ -133,69 +134,69 @@ public class LocationUnitTest {
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()));
assertEquals(one, one);
assertNotEquals(one, new Object());
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
two.setId(23);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
one.setId(23);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setName("23");
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setName("23");
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setCountryCode("11");
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setCountryCode("11");
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
final LocalDateTime now = LocalDateTime.now();
one.setSunrise(now);
one.setSunriseTime(now);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setSunrise(now);
two.setSunriseTime(now);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setSunset(now);
one.setSunsetTime(now);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setSunset(now);
two.setSunsetTime(now);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
one.setZoneOffset(ZoneOffset.UTC);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setZoneOffset(ZoneOffset.UTC);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
final Coordinate coordinate = Coordinate.withValues(33.5, -22.4);
final Coordinate coordinate = Coordinate.of(33.5, -22.4);
one.setCoordinate(coordinate);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setCoordinate(coordinate);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
}
}
@@ -22,8 +22,9 @@
package com.github.prominence.openweathermap.api.model.weather;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class RainUnitTest {
@Test
@@ -37,36 +38,43 @@ public class RainUnitTest {
public void whenSetValues_thenTheyAreSet() {
final Rain rain = Rain.withValues(0, 0);
rain.setOneHourRainLevel(33.3);
Assert.assertEquals(33.3, rain.getOneHourRainLevel(), 0.00001);
rain.setOneHourLevel(33.3);
assertEquals(33.3, rain.getOneHourLevel(), 0.00001);
rain.setThreeHourRainLevel(55.5);
Assert.assertEquals(55.5, rain.getThreeHourRainLevel(), 0.00001);
rain.setThreeHourLevel(55.5);
assertEquals(55.5, rain.getThreeHourLevel(), 0.00001);
}
@Test
public void whenCallToString_thenAllIsFine() {
Rain rain = Rain.withThreeHourLevelValue(33.5);
Assert.assertNotNull(rain.toString());
Assert.assertNotEquals("", rain.toString());
assertNotNull(rain.toString());
assertNotEquals("", rain.toString());
rain.setOneHourRainLevel(22.2);
rain.setOneHourLevel(22.2);
Assert.assertNotNull(rain.toString());
Assert.assertNotEquals("", rain.toString());
assertNotNull(rain.toString());
assertNotEquals("", rain.toString());
rain = Rain.withOneHourLevelValue(22.4);
assertNotNull(rain.toString());
assertNotEquals("", rain.toString());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidOneHourLevelValue_thenFail() {
final Rain rain = Rain.withValues(0, 0);
rain.setOneHourRainLevel(-20);
assertThrows(IllegalArgumentException.class, () -> rain.setOneHourLevel(-20));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidThreeHourLevelValue_thenFail() {
final Rain rain = Rain.withValues(0, 0);
rain.setThreeHourRainLevel(-20);
assertThrows(IllegalArgumentException.class, () -> rain.setThreeHourLevel(-20));
}
@Test
@@ -74,23 +82,23 @@ public class RainUnitTest {
final Rain first = Rain.withValues(0, 0);
final Rain second = Rain.withValues(0, 0);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
second.setThreeHourRainLevel(11.0);
second.setThreeHourLevel(11.0);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
first.setThreeHourRainLevel(11.0);
first.setThreeHourLevel(11.0);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
first.setOneHourRainLevel(333.2);
first.setOneHourLevel(333.2);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
second.setOneHourRainLevel(333.2);
second.setOneHourLevel(333.2);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
}
@Test
@@ -98,24 +106,24 @@ public class RainUnitTest {
final Rain first = Rain.withValues(0, 0);
final Rain second = Rain.withValues(0, 0);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
Assert.assertFalse(first.equals(new Object()));
assertEquals(first, second);
assertEquals(first, first);
assertNotEquals(first, new Object());
first.setOneHourRainLevel(0.34);
first.setOneHourLevel(0.34);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
second.setOneHourRainLevel(0.34);
second.setOneHourLevel(0.34);
Assert.assertTrue(first.equals(second));
assertEquals(first, second);
second.setThreeHourRainLevel(66.7);
second.setThreeHourLevel(66.7);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
first.setThreeHourRainLevel(66.7);
first.setThreeHourLevel(66.7);
Assert.assertTrue(first.equals(second));
assertEquals(first, second);
}
}
@@ -22,8 +22,9 @@
package com.github.prominence.openweathermap.api.model.weather;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class SnowUnitTest {
@Test
@@ -37,41 +38,46 @@ public class SnowUnitTest {
public void whenSetValues_thenTheyAreSet() {
final Snow snow = Snow.withValues(0, 0);
snow.setOneHourSnowLevel(33.3);
Assert.assertEquals(33.3, snow.getOneHourSnowLevel(), 0.00001);
snow.setOneHourLevel(33.3);
assertEquals(33.3, snow.getOneHourLevel(), 0.00001);
snow.setThreeHourSnowLevel(55.5);
Assert.assertEquals(55.5, snow.getThreeHourSnowLevel(), 0.00001);
snow.setThreeHourLevel(55.5);
assertEquals(55.5, snow.getThreeHourLevel(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidOneHourLevelValue_thenFail() {
final Snow rain = Snow.withValues(0, 0);
rain.setOneHourSnowLevel(-20);
assertThrows(IllegalArgumentException.class, () -> rain.setOneHourLevel(-20));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidThreeHourLevelValue_thenFail() {
final Snow rain = Snow.withValues(0, 0);
rain.setThreeHourSnowLevel(-20);
assertThrows(IllegalArgumentException.class, () -> rain.setThreeHourLevel(-20));
}
@Test
public void whenCallToString_thenAllIsFine() {
final Snow snow = Snow.withOneHourLevelValue(33.5);
Snow snow = Snow.withOneHourLevelValue(33.5);
Assert.assertNotNull(snow.toString());
Assert.assertNotEquals("", snow.toString());
assertNotNull(snow.toString());
assertNotEquals("", snow.toString());
snow.setOneHourSnowLevel(22.2);
snow.setOneHourLevel(22.2);
Assert.assertNotNull(snow.toString());
Assert.assertNotEquals("", snow.toString());
assertNotNull(snow.toString());
assertNotEquals("", snow.toString());
snow.setThreeHourSnowLevel(33.2);
snow.setThreeHourLevel(33.2);
Assert.assertNotNull(snow.toString());
Assert.assertNotEquals("", snow.toString());
assertNotNull(snow.toString());
assertNotEquals("", snow.toString());
snow = Snow.withThreeHourLevelValue(33.2);
assertNotNull(snow.toString());
assertNotEquals("", snow.toString());
}
@Test
@@ -79,23 +85,23 @@ public class SnowUnitTest {
final Snow first = Snow.withValues(0, 0);
final Snow second = Snow.withValues(0, 0);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
second.setThreeHourSnowLevel(11.0);
second.setThreeHourLevel(11.0);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
first.setThreeHourSnowLevel(11.0);
first.setThreeHourLevel(11.0);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
first.setOneHourSnowLevel(333.2);
first.setOneHourLevel(333.2);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
second.setOneHourSnowLevel(333.2);
second.setOneHourLevel(333.2);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
}
@Test
@@ -103,24 +109,24 @@ public class SnowUnitTest {
final Snow first = Snow.withValues(0, 0);
final Snow second = Snow.withValues(0, 0);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
Assert.assertFalse(first.equals(new Object()));
assertEquals(first, second);
assertEquals(first, first);
assertNotEquals(first, new Object());
first.setOneHourSnowLevel(0.34);
first.setOneHourLevel(0.34);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
second.setOneHourSnowLevel(0.34);
second.setOneHourLevel(0.34);
Assert.assertTrue(first.equals(second));
assertEquals(first, second);
second.setThreeHourSnowLevel(66.7);
second.setThreeHourLevel(66.7);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
first.setThreeHourSnowLevel(66.7);
first.setThreeHourLevel(66.7);
Assert.assertTrue(first.equals(second));
assertEquals(first, second);
}
}
@@ -22,155 +22,98 @@
package com.github.prominence.openweathermap.api.model.weather;
import com.github.prominence.openweathermap.api.model.AtmosphericPressure;
import com.github.prominence.openweathermap.api.model.Clouds;
import com.github.prominence.openweathermap.api.model.Humidity;
import com.github.prominence.openweathermap.api.model.Temperature;
import org.junit.Assert;
import org.junit.Test;
import com.github.prominence.openweathermap.api.model.*;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.*;
public class WeatherUnitTest {
@Test
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
Weather.forValue("state", "desc");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithoutState_thenThrowAnException() {
Weather.forValue(null, "desc");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithoutDescription_thenThrowAnException() {
Weather.forValue("state", null);
}
@Test
public void whenSetState_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
weather.setState("test");
Assert.assertEquals("test", weather.getState());
}
@Test(expected = IllegalArgumentException.class)
public void whenSetNullState_thenThrowAnException() {
final Weather weather = Weather.forValue("state", "desc");
weather.setState(null);
}
@Test
public void whenSetDescription_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
weather.setDescription("test");
Assert.assertEquals("test", weather.getDescription());
}
@Test(expected = IllegalArgumentException.class)
public void whenSetNullDescription_thenThrowAnException() {
final Weather weather = Weather.forValue("state", "desc");
weather.setDescription(null);
}
@Test
public void whenSetIconId_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
Assert.assertNull(weather.getWeatherIconId());
Assert.assertNull(weather.getWeatherIconUrl());
weather.setWeatherIconId("11d");
Assert.assertEquals("11d", weather.getWeatherIconId());
Assert.assertNotNull(weather.getWeatherIconUrl());
}
@Test
public void whenSetRequestedOn_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Weather weather = new Weather();
final LocalDateTime now = LocalDateTime.now();
weather.setCalculatedOn(now);
weather.setCalculationTime(now);
Assert.assertEquals(now, weather.getCalculatedOn());
assertEquals(now, weather.getCalculationTime());
}
@Test
public void whenSetTemperature_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Weather weather = new Weather();
final Temperature temperature = Temperature.withValue(22.3, "a");
weather.setTemperature(temperature);
Assert.assertEquals(temperature, weather.getTemperature());
assertEquals(temperature, weather.getTemperature());
}
@Test
public void whenSetPressure_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Weather weather = new Weather();
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.2);
weather.setAtmosphericPressure(atmosphericPressure);
Assert.assertEquals(atmosphericPressure, weather.getAtmosphericPressure());
assertEquals(atmosphericPressure, weather.getAtmosphericPressure());
}
@Test
public void whenSetHumidity_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Weather weather = new Weather();
final Humidity humidity = Humidity.withValue((byte) 44);
weather.setHumidity(humidity);
Assert.assertEquals(humidity, weather.getHumidity());
assertEquals(humidity, weather.getHumidity());
}
@Test
public void whenSetWind_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Weather weather = new Weather();
final Wind wind = Wind.withValue(22.2, "a");
weather.setWind(wind);
Assert.assertEquals(wind, weather.getWind());
assertEquals(wind, weather.getWind());
}
@Test
public void whenSetRain_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Weather weather = new Weather();
final Rain rain = Rain.withValues(0, 0);
weather.setRain(rain);
Assert.assertEquals(rain, weather.getRain());
assertEquals(rain, weather.getRain());
}
@Test
public void whenSetSnow_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Weather weather = new Weather();
final Snow snow = Snow.withValues(0, 0);
weather.setSnow(snow);
Assert.assertEquals(snow, weather.getSnow());
assertEquals(snow, weather.getSnow());
}
@Test
public void whenSetClouds_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Weather weather = new Weather();
final Clouds clouds = Clouds.withValue((byte) 33);
weather.setClouds(clouds);
Assert.assertEquals(clouds, weather.getClouds());
assertEquals(clouds, weather.getClouds());
}
@Test
public void whenSetLocation_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Weather weather = new Weather();
final Location location = Location.withValues(22, "asd");
weather.setLocation(location);
Assert.assertEquals(location, weather.getLocation());
assertEquals(location, weather.getLocation());
}
@Test
public void whenCallToString_thenAllIsFine() {
final Weather weather = Weather.forValue("state", "desc");
final Weather weather = new Weather();
final Location location = Location.withValues(12312, "asd");
final Temperature temperature = Temperature.withValue(33.2, "asd");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(44.4);
@@ -178,154 +121,155 @@ public class WeatherUnitTest {
final Rain rain = Rain.withOneHourLevelValue(33.2);
final Snow snow = Snow.withOneHourLevelValue(33.1);
Assert.assertNotEquals("", weather.toString());
Assert.assertNotNull(weather.toString());
assertEquals("", weather.toString());
assertNotNull(weather.toString());
weather.setLocation(location);
Assert.assertNotEquals("", weather.toString());
Assert.assertNotNull(weather.toString());
assertNotEquals("", weather.toString());
assertNotNull(weather.toString());
location.setCountryCode("3d");
Assert.assertNotEquals("", weather.toString());
Assert.assertNotNull(weather.toString());
assertNotEquals("", weather.toString());
assertNotNull(weather.toString());
weather.setTemperature(temperature);
Assert.assertNotEquals("", weather.toString());
Assert.assertNotNull(weather.toString());
assertNotEquals("", weather.toString());
assertNotNull(weather.toString());
weather.setAtmosphericPressure(atmosphericPressure);
Assert.assertNotEquals("", weather.toString());
Assert.assertNotNull(weather.toString());
assertNotEquals("", weather.toString());
assertNotNull(weather.toString());
weather.setClouds(clouds);
Assert.assertNotEquals("", weather.toString());
Assert.assertNotNull(weather.toString());
assertNotEquals("", weather.toString());
assertNotNull(weather.toString());
weather.setRain(rain);
Assert.assertNotEquals("", weather.toString());
Assert.assertNotNull(weather.toString());
assertNotEquals("", weather.toString());
assertNotNull(weather.toString());
weather.setRain(Rain.withThreeHourLevelValue(33));
assertNotEquals("", weather.toString());
assertNotNull(weather.toString());
weather.setSnow(snow);
Assert.assertNotEquals("", weather.toString());
Assert.assertNotNull(weather.toString());
assertNotEquals("", weather.toString());
assertNotNull(weather.toString());
weather.setSnow(Snow.withThreeHourLevelValue(44));
assertNotEquals("", weather.toString());
assertNotNull(weather.toString());
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final Weather one = Weather.forValue("state", "desc");
final Weather two = Weather.forValue("state", "desc");
final Weather one = new Weather();
final Weather two = new Weather();
Assert.assertEquals(one.hashCode(), two.hashCode());
assertEquals(one.hashCode(), two.hashCode());
two.setDescription("112");
two.setCalculationTime(LocalDateTime.now());
Assert.assertNotEquals(one.hashCode(), two.hashCode());
assertNotEquals(one.hashCode(), two.hashCode());
}
@Test
public void whenCheckEquality_thenAllIsFine() {
final Weather one = Weather.forValue("state", "desc");
final Weather two = Weather.forValue("state1", "desc1");
final Weather one = new Weather();
final Weather two = new Weather();
Assert.assertTrue(one.equals(one));
Assert.assertFalse(one.equals(new Object()));
Assert.assertFalse(one.equals(two));
two.setState("state");
Assert.assertFalse(one.equals(two));
two.setDescription("desc");
Assert.assertTrue(one.equals(two));
one.setWeatherIconId("1");
Assert.assertFalse(one.equals(two));
two.setWeatherIconId("1");
Assert.assertTrue(one.equals(two));
assertEquals(one, one);
assertNotEquals(one, new Object());
assertEquals(one, two);
final LocalDateTime now = LocalDateTime.now();
one.setCalculatedOn(now);
one.setCalculationTime(now);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setCalculatedOn(now);
two.setCalculationTime(now);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
final Temperature temperature = Temperature.withValue(33.2, "as");
one.setTemperature(temperature);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setTemperature(temperature);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
one.setWeatherState(weatherState);
assertNotEquals(one, two);
two.setWeatherState(weatherState);
assertEquals(one, two);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.33);
one.setAtmosphericPressure(atmosphericPressure);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setAtmosphericPressure(atmosphericPressure);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
final Humidity humidity = Humidity.withValue((byte) 33);
one.setHumidity(humidity);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setHumidity(humidity);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
final Wind wind = Wind.withValue(33.6, "asd");
one.setWind(wind);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setWind(wind);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
final Rain rain = Rain.withValues(0, 0);
one.setRain(rain);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setRain(rain);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
final Snow snow = Snow.withValues(0, 0);
one.setSnow(snow);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setSnow(snow);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
final Clouds clouds = Clouds.withValue((byte) 33);
one.setClouds(clouds);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setClouds(clouds);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
final Location location = Location.withValues(231, "asda");
one.setLocation(location);
Assert.assertFalse(one.equals(two));
assertNotEquals(one, two);
two.setLocation(location);
Assert.assertTrue(one.equals(two));
assertEquals(one, two);
}
}
@@ -22,103 +22,106 @@
package com.github.prominence.openweathermap.api.model.weather;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class WindUnitTest {
@Test
public void whenCreateWindWithValidArgs_thenValueIsSet() {
Assert.assertEquals(44.0, Wind.withValue(44, "ms").getSpeed(), 0.00001);
assertEquals(44.0, Wind.withValue(44, "ms").getSpeed(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateWindWithInvalidSpeedArg_thenThrowAnException() {
Wind.withValue(-21, "a");
assertThrows(IllegalArgumentException.class, () -> Wind.withValue(-21, "a"));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenCreateWindWithInvalidUnitArg_thenThrowAnException() {
Wind.withValue(342, null);
assertThrows(IllegalArgumentException.class, () -> Wind.withValue(342, null));
}
@Test
public void whenSetValidSpeed_thenValueIsSet() {
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
assertEquals(33, wind.getSpeed(), 0.00001);
wind.setSpeed(0);
Assert.assertEquals(0, wind.getSpeed(), 0.00001);
assertEquals(0, wind.getSpeed(), 0.00001);
wind.setSpeed(3656);
Assert.assertEquals(3656, wind.getSpeed(), 0.00001);
assertEquals(3656, wind.getSpeed(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidSpeedBelow0_thenThrowAnException() {
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
assertEquals(33, wind.getSpeed(), 0.00001);
wind.setSpeed(-22);
assertThrows(IllegalArgumentException.class, () -> wind.setSpeed(-22));
}
@Test
public void whenSetValidDegrees_thenValueIsSet() {
final Wind wind = Wind.withValue(33, "as");
Assert.assertNull(wind.getDegrees());
assertNull(wind.getDegrees());
wind.setDegrees(22);
Assert.assertEquals(22, wind.getDegrees(), 0.00001);
assertEquals(22, wind.getDegrees(), 0.00001);
wind.setDegrees(0);
Assert.assertEquals(0, wind.getDegrees(), 0.00001);
assertEquals(0, wind.getDegrees(), 0.00001);
wind.setDegrees(360);
Assert.assertEquals(360, wind.getDegrees(), 0.00001);
assertEquals(360, wind.getDegrees(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidDegreesBelow0_thenThrowAnException() {
final Wind wind = Wind.withValue(33, "as");
wind.setDegrees(-32);
assertThrows(IllegalArgumentException.class, () -> wind.setDegrees(-32));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidDegreesAbove360_thenThrowAnException() {
final Wind wind = Wind.withValue(33, "as");
wind.setDegrees(378);
assertThrows(IllegalArgumentException.class, () -> wind.setDegrees(378));
}
@Test
public void whenSetNonNullUnit_thenValueIsSet() {
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(wind.getUnit(), "as");
assertEquals(wind.getUnit(), "as");
wind.setUnit("myUnit");
Assert.assertEquals(wind.getUnit(), "myUnit");
assertEquals(wind.getUnit(), "myUnit");
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetNullUnit_thenThrowAnException() {
final Wind wind = Wind.withValue(33, "as");
wind.setUnit(null);
assertThrows(IllegalArgumentException.class, () -> wind.setUnit(null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void whenSetInvalidGustValue_thenThrowAnException() {
final Wind wind = Wind.withValue(33, "as");
wind.setGust(-50);
assertThrows(IllegalArgumentException.class, () -> wind.setGust(-50));
}
@Test
@@ -127,23 +130,23 @@ public class WindUnitTest {
wind.setGust(30);
Assert.assertEquals(30, wind.getGust(), 0.00001);
assertEquals(30, wind.getGust(), 0.00001);
}
@Test
public void whenCallToString_thenAllIsFine() {
final Wind wind = Wind.withValue(302, "a");
Assert.assertNotNull(wind.toString());
assertNotNull(wind.toString());
wind.setDegrees(22);
Assert.assertNotNull(wind.toString());
Assert.assertNotEquals("", wind.toString());
assertNotNull(wind.toString());
assertNotEquals("", wind.toString());
wind.setGust(20);
Assert.assertNotNull(wind.toString());
Assert.assertNotEquals("", wind.toString());
assertNotNull(wind.toString());
assertNotEquals("", wind.toString());
}
@Test
@@ -151,23 +154,23 @@ public class WindUnitTest {
final Wind first = Wind.withValue(22, "a");
final Wind second = Wind.withValue(22, "b");
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
second.setUnit("a");
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
second.setSpeed(33);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
first.setSpeed(333);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
assertNotEquals(first.hashCode(), second.hashCode());
first.setSpeed(33);
Assert.assertEquals(first.hashCode(), second.hashCode());
assertEquals(first.hashCode(), second.hashCode());
}
@Test
@@ -175,32 +178,36 @@ public class WindUnitTest {
final Wind first = Wind.withValue(11, "a");
final Wind second = Wind.withValue(11, "a");
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
Assert.assertFalse(first.equals(new Object()));
assertEquals(first, second);
assertEquals(first, first);
assertNotEquals(first, new Object());
first.setDegrees(34);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
second.setDegrees(34);
Assert.assertTrue(first.equals(second));
assertEquals(first, second);
second.setUnit("v");
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
first.setUnit("v");
Assert.assertTrue(first.equals(second));
assertEquals(first, second);
first.setGust(4);
Assert.assertFalse(first.equals(second));
assertNotEquals(first, second);
second.setGust(4);
Assert.assertTrue(first.equals(second));
assertEquals(first, second);
first.setSpeed(32);
assertNotEquals(first, second);
}
}
@@ -31,12 +31,13 @@ import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
import com.github.prominence.openweathermap.api.model.forecast.WeatherForecast;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static org.junit.jupiter.api.Assertions.*;
public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
@Test
public void whenGetForecastByCityNameRequestAsJava_thenReturnNotNull() {
@@ -49,17 +50,16 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(forecast);
Assert.assertNotNull(forecast.getLocation());
Assert.assertNotNull(forecast.getWeatherForecasts());
assertNotNull(forecast);
assertNotNull(forecast.getLocation());
assertNotNull(forecast.getWeatherForecasts());
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
Assert.assertNotNull(weatherForecast.getState());
Assert.assertNotNull(weatherForecast.getDescription());
Assert.assertNotNull(weatherForecast.getForecastTime());
Assert.assertNotNull(weatherForecast.getTemperature());
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
Assert.assertNotNull(weatherForecast.getHumidity());
Assert.assertNotNull(weatherForecast.getWind());
assertNotNull(weatherForecast.getWeatherState());
assertNotNull(weatherForecast.getForecastTime());
assertNotNull(weatherForecast.getTemperature());
assertNotNull(weatherForecast.getAtmosphericPressure());
assertNotNull(weatherForecast.getHumidity());
assertNotNull(weatherForecast.getWind());
}
}
@@ -74,7 +74,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(forecastJson.startsWith("{"));
assertTrue(forecastJson.startsWith("{"));
}
@Test
@@ -88,7 +88,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(forecastXml.startsWith("<"));
assertTrue(forecastXml.startsWith("<"));
}
@Test
@@ -102,17 +102,16 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(forecast);
Assert.assertNotNull(forecast.getLocation());
Assert.assertNotNull(forecast.getWeatherForecasts());
assertNotNull(forecast);
assertNotNull(forecast.getLocation());
assertNotNull(forecast.getWeatherForecasts());
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
Assert.assertNotNull(weatherForecast.getState());
Assert.assertNotNull(weatherForecast.getDescription());
Assert.assertNotNull(weatherForecast.getForecastTime());
Assert.assertNotNull(weatherForecast.getTemperature());
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
Assert.assertNotNull(weatherForecast.getHumidity());
Assert.assertNotNull(weatherForecast.getWind());
assertNotNull(weatherForecast.getWeatherState());
assertNotNull(weatherForecast.getForecastTime());
assertNotNull(weatherForecast.getTemperature());
assertNotNull(weatherForecast.getAtmosphericPressure());
assertNotNull(weatherForecast.getHumidity());
assertNotNull(weatherForecast.getWind());
}
}
@@ -127,7 +126,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(forecastJson.startsWith("{"));
assertTrue(forecastJson.startsWith("{"));
}
@Test
@@ -141,7 +140,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(forecastXml.startsWith("<"));
assertTrue(forecastXml.startsWith("<"));
}
@Test
@@ -155,17 +154,16 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(forecast);
Assert.assertNotNull(forecast.getLocation());
Assert.assertNotNull(forecast.getWeatherForecasts());
assertNotNull(forecast);
assertNotNull(forecast.getLocation());
assertNotNull(forecast.getWeatherForecasts());
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
Assert.assertNotNull(weatherForecast.getState());
Assert.assertNotNull(weatherForecast.getDescription());
Assert.assertNotNull(weatherForecast.getForecastTime());
Assert.assertNotNull(weatherForecast.getTemperature());
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
Assert.assertNotNull(weatherForecast.getHumidity());
Assert.assertNotNull(weatherForecast.getWind());
assertNotNull(weatherForecast.getWeatherState());
assertNotNull(weatherForecast.getForecastTime());
assertNotNull(weatherForecast.getTemperature());
assertNotNull(weatherForecast.getAtmosphericPressure());
assertNotNull(weatherForecast.getHumidity());
assertNotNull(weatherForecast.getWind());
}
}
@@ -180,7 +178,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(forecastJson.startsWith("{"));
assertTrue(forecastJson.startsWith("{"));
}
@Test
@@ -193,7 +191,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(forecastXml.startsWith("<"));
assertTrue(forecastXml.startsWith("<"));
}
@Test
@@ -207,17 +205,16 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(forecast);
Assert.assertNotNull(forecast.getLocation());
Assert.assertNotNull(forecast.getWeatherForecasts());
assertNotNull(forecast);
assertNotNull(forecast.getLocation());
assertNotNull(forecast.getWeatherForecasts());
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
Assert.assertNotNull(weatherForecast.getState());
Assert.assertNotNull(weatherForecast.getDescription());
Assert.assertNotNull(weatherForecast.getForecastTime());
Assert.assertNotNull(weatherForecast.getTemperature());
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
Assert.assertNotNull(weatherForecast.getHumidity());
Assert.assertNotNull(weatherForecast.getWind());
assertNotNull(weatherForecast.getWeatherState());
assertNotNull(weatherForecast.getForecastTime());
assertNotNull(weatherForecast.getTemperature());
assertNotNull(weatherForecast.getAtmosphericPressure());
assertNotNull(weatherForecast.getHumidity());
assertNotNull(weatherForecast.getWind());
}
}
@@ -232,7 +229,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(forecastJson.startsWith("{"));
assertTrue(forecastJson.startsWith("{"));
}
@Test
@@ -245,31 +242,30 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(forecastXml.startsWith("<"));
assertTrue(forecastXml.startsWith("<"));
}
@Test
public void whenGetForecastByCoordinatesRequestAsJava_thenReturnNotNull() {
final Forecast forecast = getClient()
.forecast5Day3HourStep()
.byCoordinate(Coordinate.withValues(5, 5))
.byCoordinate(Coordinate.of(5, 5))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.count(15)
.retrieve()
.asJava();
Assert.assertNotNull(forecast);
Assert.assertNotNull(forecast.getLocation());
Assert.assertNotNull(forecast.getWeatherForecasts());
assertNotNull(forecast);
assertNotNull(forecast.getLocation());
assertNotNull(forecast.getWeatherForecasts());
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
Assert.assertNotNull(weatherForecast.getState());
Assert.assertNotNull(weatherForecast.getDescription());
Assert.assertNotNull(weatherForecast.getForecastTime());
Assert.assertNotNull(weatherForecast.getTemperature());
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
Assert.assertNotNull(weatherForecast.getHumidity());
Assert.assertNotNull(weatherForecast.getWind());
assertNotNull(weatherForecast.getWeatherState());
assertNotNull(weatherForecast.getForecastTime());
assertNotNull(weatherForecast.getTemperature());
assertNotNull(weatherForecast.getAtmosphericPressure());
assertNotNull(weatherForecast.getHumidity());
assertNotNull(weatherForecast.getWind());
}
}
@@ -277,27 +273,27 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
public void whenGetForecastByCoordinatesRequestAsJSON_thenReturnNotNull() {
final String forecastJson = getClient()
.forecast5Day3HourStep()
.byCoordinate(Coordinate.withValues(5, 5))
.byCoordinate(Coordinate.of(5, 5))
.language(Language.SPANISH)
.unitSystem(UnitSystem.IMPERIAL)
.count(15)
.retrieve()
.asJSON();
Assert.assertTrue(forecastJson.startsWith("{"));
assertTrue(forecastJson.startsWith("{"));
}
@Test
public void whenGetForecastByCoordinatesRequestAsXML_thenReturnNotNull() {
final String forecastXml = getClient()
.forecast5Day3HourStep()
.byCoordinate(Coordinate.withValues(5, 5))
.byCoordinate(Coordinate.of(5, 5))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asXML();
Assert.assertTrue(forecastXml.startsWith("<"));
assertTrue(forecastXml.startsWith("<"));
}
@Test
@@ -311,17 +307,16 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(forecast);
Assert.assertNotNull(forecast.getLocation());
Assert.assertNotNull(forecast.getWeatherForecasts());
assertNotNull(forecast);
assertNotNull(forecast.getLocation());
assertNotNull(forecast.getWeatherForecasts());
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
Assert.assertNotNull(weatherForecast.getState());
Assert.assertNotNull(weatherForecast.getDescription());
Assert.assertNotNull(weatherForecast.getForecastTime());
Assert.assertNotNull(weatherForecast.getTemperature());
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
Assert.assertNotNull(weatherForecast.getHumidity());
Assert.assertNotNull(weatherForecast.getWind());
assertNotNull(weatherForecast.getWeatherState());
assertNotNull(weatherForecast.getForecastTime());
assertNotNull(weatherForecast.getTemperature());
assertNotNull(weatherForecast.getAtmosphericPressure());
assertNotNull(weatherForecast.getHumidity());
assertNotNull(weatherForecast.getWind());
}
}
@@ -336,7 +331,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(forecastJson.startsWith("{"));
assertTrue(forecastJson.startsWith("{"));
}
@Test
@@ -349,7 +344,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(forecastXml.startsWith("<"));
assertTrue(forecastXml.startsWith("<"));
}
@Test
@@ -363,17 +358,16 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(forecast);
Assert.assertNotNull(forecast.getLocation());
Assert.assertNotNull(forecast.getWeatherForecasts());
assertNotNull(forecast);
assertNotNull(forecast.getLocation());
assertNotNull(forecast.getWeatherForecasts());
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
Assert.assertNotNull(weatherForecast.getState());
Assert.assertNotNull(weatherForecast.getDescription());
Assert.assertNotNull(weatherForecast.getForecastTime());
Assert.assertNotNull(weatherForecast.getTemperature());
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
Assert.assertNotNull(weatherForecast.getHumidity());
Assert.assertNotNull(weatherForecast.getWind());
assertNotNull(weatherForecast.getWeatherState());
assertNotNull(weatherForecast.getForecastTime());
assertNotNull(weatherForecast.getTemperature());
assertNotNull(weatherForecast.getAtmosphericPressure());
assertNotNull(weatherForecast.getHumidity());
assertNotNull(weatherForecast.getWind());
}
}
@@ -388,7 +382,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(forecastJson.startsWith("{"));
assertTrue(forecastJson.startsWith("{"));
}
@Test
@@ -401,7 +395,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(forecastXml.startsWith("<"));
assertTrue(forecastXml.startsWith("<"));
}
@Test
@@ -415,7 +409,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieveAsync()
.asJava();
Assert.assertNotNull(forecastFuture);
assertNotNull(forecastFuture);
System.out.println(forecastFuture.get());
}
@@ -430,7 +424,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieveAsync()
.asJSON();
Assert.assertNotNull(forecastFuture);
assertNotNull(forecastFuture);
System.out.println(forecastFuture.get());
}
@@ -445,26 +439,30 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
.retrieveAsync()
.asXML();
Assert.assertNotNull(forecastFuture);
assertNotNull(forecastFuture);
System.out.println(forecastFuture.get());
}
@Test(expected = InvalidAuthTokenException.class)
@Test
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
client
.forecast5Day3HourStep()
.byCityId(350001514)
.retrieve()
.asJSON();
assertThrows(InvalidAuthTokenException.class, () ->
client
.forecast5Day3HourStep()
.byCityId(350001514)
.retrieve()
.asJSON()
);
}
@Test(expected = NoDataFoundException.class)
@Test
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
getClient()
.forecast5Day3HourStep()
.byCityName("invalidCity")
.retrieve()
.asJava();
assertThrows(NoDataFoundException.class, () ->
getClient()
.forecast5Day3HourStep()
.byCityName("invalidCity")
.retrieve()
.asJava()
);
}
}
@@ -0,0 +1,135 @@
/*
* 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.onecall.current;
import com.github.prominence.openweathermap.api.ApiTest;
import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.OneCallResultOptions;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
import org.junit.jupiter.api.Test;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static org.junit.jupiter.api.Assertions.*;
public class CurrentWeatherOneCallIntegrationTest extends ApiTest {
@Test
public void whenRetrieveCurrentOneCallResponseAsJava_thenOk() {
final CurrentWeatherData currentWeatherData = getClient()
.oneCall()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assertNotNull(currentWeatherData);
}
@Test
public void whenRetrieveCurrentOneCallResponseAsJSON_thenOk() {
final String responseJson = getClient()
.oneCall()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJSON();
assertNotNull(responseJson);
assertNotEquals("", responseJson);
System.out.println(responseJson);
}
@Test
public void whenRetrieveCurrentOneCallResponseWithExclusionAsJava_thenOk() {
final CurrentWeatherData currentWeatherData = getClient()
.oneCall()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.exclude(OneCallResultOptions.CURRENT, OneCallResultOptions.MINUTELY)
.retrieve()
.asJava();
assertNotNull(currentWeatherData);
assertNull(currentWeatherData.getCurrent());
assertNull(currentWeatherData.getMinutelyList());
}
@Test
public void whenRetrieveCurrentOneCallAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
final CompletableFuture<CurrentWeatherData> currentWeatherDataFuture = getClient()
.oneCall()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
.asJava();
assertNotNull(currentWeatherDataFuture);
assertNotNull(currentWeatherDataFuture.get());
}
@Test
public void whenRetrieveCurrentOneCallAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
final CompletableFuture<String> responseJsonFuture = getClient()
.oneCall()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
.asJSON();
assertNotNull(responseJsonFuture);
final String responseJson = responseJsonFuture.get();
assertNotNull(responseJson);
System.out.println(responseJson);
}
@Test
public void whenRequestOnecallWithInvalidApiKey_thenThrowAnException() {
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
assertThrows(InvalidAuthTokenException.class, () ->
client
.oneCall()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJSON()
);
}
}
@@ -0,0 +1,119 @@
/*
* 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.onecall.historical;
import com.github.prominence.openweathermap.api.ApiTest;
import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static org.junit.jupiter.api.Assertions.*;
public class HistoricalWeatherOneCallIntegrationTest extends ApiTest {
@Test
public void whenRetrieveHistoricalOneCallResponseAsJava_thenOk() {
final HistoricalWeatherData historicalWeatherData = getClient()
.oneCall()
.historical()
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assertNotNull(historicalWeatherData);
}
@Test
public void whenRetrieveHistoricalOneCallResponseAsJSON_thenOk() {
final String responseJson = getClient()
.oneCall()
.historical()
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJSON();
assertNotNull(responseJson);
assertNotEquals("", responseJson);
System.out.println(responseJson);
}
@Test
public void whenRetrieveHistoricalOneCallAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
final CompletableFuture<HistoricalWeatherData> historicalWeatherDataFuture = getClient()
.oneCall()
.historical()
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
.asJava();
assertNotNull(historicalWeatherDataFuture);
assertNotNull(historicalWeatherDataFuture.get());
}
@Test
public void whenRetrieveHistoricalOneCallAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
final CompletableFuture<String> responseJsonFuture = getClient()
.oneCall()
.historical()
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
.asJSON();
assertNotNull(responseJsonFuture);
final String responseJson = responseJsonFuture.get();
assertNotEquals("", responseJson);
System.out.println(responseJson);
}
@Test
public void whenRequestOnecallWithInvalidApiKey_thenThrowAnException() {
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
assertThrows(InvalidAuthTokenException.class, () ->
client
.oneCall()
.historical()
.byCoordinateAndTimestamp(Coordinate.of(53.54, 27.34), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJSON()
);
}
}
@@ -31,13 +31,14 @@ import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
import com.github.prominence.openweathermap.api.model.weather.Weather;
import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static org.junit.jupiter.api.Assertions.*;
public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
@Test
public void whenGetMultipleCurrentWeatherByCoordinateRectangleRequestAsJava_thenReturnNotNull() {
@@ -58,17 +59,16 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(weatherList);
assertNotNull(weatherList);
for (Weather weather : weatherList) {
Assert.assertNotNull(weather);
Assert.assertNotNull(weather.getState());
Assert.assertNotNull(weather.getDescription());
Assert.assertNotNull(weather.getCalculatedOn());
Assert.assertNotNull(weather.getTemperature());
Assert.assertNotNull(weather.getLocation());
Assert.assertNotNull(weather.getAtmosphericPressure());
Assert.assertNotNull(weather.getHumidity());
Assert.assertNotNull(weather.getWind());
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
}
}
@@ -83,7 +83,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(weatherJson.startsWith("{"));
assertTrue(weatherJson.startsWith("{"));
}
@Test
@@ -91,24 +91,23 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJava();
Assert.assertNotNull(weatherList);
assertNotNull(weatherList);
for (Weather weather : weatherList) {
System.out.println(weather);
Assert.assertNotNull(weather);
Assert.assertNotNull(weather.getState());
Assert.assertNotNull(weather.getDescription());
Assert.assertNotNull(weather.getCalculatedOn());
Assert.assertNotNull(weather.getTemperature());
Assert.assertNotNull(weather.getLocation());
Assert.assertNotNull(weather.getAtmosphericPressure());
Assert.assertNotNull(weather.getHumidity());
Assert.assertNotNull(weather.getWind());
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
}
}
@@ -117,13 +116,13 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherJson = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJSON();
Assert.assertTrue(weatherJson.startsWith("{"));
assertTrue(weatherJson.startsWith("{"));
}
@Test
@@ -131,13 +130,13 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherXml = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asXML();
Assert.assertTrue(weatherXml.startsWith("<"));
assertTrue(weatherXml.startsWith("<"));
System.out.println(weatherXml);
}
@@ -146,24 +145,23 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJava();
Assert.assertNotNull(weatherList);
assertNotNull(weatherList);
for (Weather weather : weatherList) {
System.out.println(weather);
Assert.assertNotNull(weather);
Assert.assertNotNull(weather.getState());
Assert.assertNotNull(weather.getDescription());
Assert.assertNotNull(weather.getCalculatedOn());
Assert.assertNotNull(weather.getTemperature());
Assert.assertNotNull(weather.getLocation());
Assert.assertNotNull(weather.getAtmosphericPressure());
Assert.assertNotNull(weather.getHumidity());
Assert.assertNotNull(weather.getWind());
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
}
}
@@ -172,13 +170,13 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherJson = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJSON();
Assert.assertTrue(weatherJson.startsWith("{"));
assertTrue(weatherJson.startsWith("{"));
}
@Test
@@ -186,13 +184,13 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherXml = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asXML();
Assert.assertTrue(weatherXml.startsWith("<"));
assertTrue(weatherXml.startsWith("<"));
}
@Test
@@ -200,15 +198,15 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final CompletableFuture<List<Weather>> weatherListFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
.asJava();
Assert.assertNotNull(weatherListFuture);
assertNotNull(weatherListFuture);
List<Weather> weatherList = weatherListFuture.get();
Assert.assertTrue(weatherList.size() > 0);
assertTrue(weatherList.size() > 0);
System.out.println(weatherList);
}
@@ -217,34 +215,38 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
.asJSON();
Assert.assertNotNull(weatherFuture);
assertNotNull(weatherFuture);
System.out.println(weatherFuture.get());
}
@Test(expected = InvalidAuthTokenException.class)
@Test
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
client
.currentWeather()
.single()
.byCityName("London")
.retrieve()
.asJSON();
assertThrows(InvalidAuthTokenException.class, () ->
client
.currentWeather()
.single()
.byCityName("London")
.retrieve()
.asJSON()
);
}
@Test(expected = NoDataFoundException.class)
@Test
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
getClient()
.currentWeather()
.single()
.byCityName("InvalidCity")
.retrieve()
.asJava();
assertThrows(NoDataFoundException.class, () ->
getClient()
.currentWeather()
.single()
.byCityName("InvalidCity")
.retrieve()
.asJava()
);
}
}
@@ -30,12 +30,13 @@ import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.weather.Weather;
import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static org.junit.jupiter.api.Assertions.*;
public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
@Test
public void whenGetSingleCurrentWeatherByCityNameRequestAsJava_thenReturnNotNull() {
@@ -48,15 +49,14 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(weather);
Assert.assertNotNull(weather.getState());
Assert.assertNotNull(weather.getDescription());
Assert.assertNotNull(weather.getCalculatedOn());
Assert.assertNotNull(weather.getTemperature());
Assert.assertNotNull(weather.getLocation());
Assert.assertNotNull(weather.getAtmosphericPressure());
Assert.assertNotNull(weather.getHumidity());
Assert.assertNotNull(weather.getWind());
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
System.out.println(weather);
}
@@ -71,7 +71,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(weatherJson.startsWith("{"));
assertTrue(weatherJson.startsWith("{"));
}
@Test
@@ -85,7 +85,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(weatherXml.startsWith("<"));
assertTrue(weatherXml.startsWith("<"));
}
@Test
@@ -99,7 +99,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asHTML();
Assert.assertTrue(weatherHtml.startsWith("<"));
assertTrue(weatherHtml.startsWith("<"));
}
@Test
@@ -113,15 +113,14 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(weather);
Assert.assertNotNull(weather.getState());
Assert.assertNotNull(weather.getDescription());
Assert.assertNotNull(weather.getCalculatedOn());
Assert.assertNotNull(weather.getTemperature());
Assert.assertNotNull(weather.getLocation());
Assert.assertNotNull(weather.getAtmosphericPressure());
Assert.assertNotNull(weather.getHumidity());
Assert.assertNotNull(weather.getWind());
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
System.out.println(weather);
}
@@ -136,7 +135,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(weatherJson.startsWith("{"));
assertTrue(weatherJson.startsWith("{"));
}
@Test
@@ -150,7 +149,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(weatherXml.startsWith("<"));
assertTrue(weatherXml.startsWith("<"));
}
@Test
@@ -164,7 +163,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asHTML();
Assert.assertTrue(weatherHtml.startsWith("<"));
assertTrue(weatherHtml.startsWith("<"));
}
@Test
@@ -178,15 +177,14 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(weather);
Assert.assertNotNull(weather.getState());
Assert.assertNotNull(weather.getDescription());
Assert.assertNotNull(weather.getCalculatedOn());
Assert.assertNotNull(weather.getTemperature());
Assert.assertNotNull(weather.getLocation());
Assert.assertNotNull(weather.getAtmosphericPressure());
Assert.assertNotNull(weather.getHumidity());
Assert.assertNotNull(weather.getWind());
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
System.out.println(weather);
}
@@ -201,7 +199,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(weatherJson.startsWith("{"));
assertTrue(weatherJson.startsWith("{"));
}
@Test
@@ -215,7 +213,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(weatherXml.startsWith("<"));
assertTrue(weatherXml.startsWith("<"));
}
@Test
@@ -229,7 +227,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asHTML();
Assert.assertTrue(weatherHtml.startsWith("<"));
assertTrue(weatherHtml.startsWith("<"));
}
@Test
@@ -242,15 +240,14 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(weather);
Assert.assertNotNull(weather.getState());
Assert.assertNotNull(weather.getDescription());
Assert.assertNotNull(weather.getCalculatedOn());
Assert.assertNotNull(weather.getTemperature());
Assert.assertNotNull(weather.getLocation());
Assert.assertNotNull(weather.getAtmosphericPressure());
Assert.assertNotNull(weather.getHumidity());
Assert.assertNotNull(weather.getWind());
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
System.out.println(weather);
}
@@ -264,7 +261,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(weatherJson.startsWith("{"));
assertTrue(weatherJson.startsWith("{"));
}
@Test
@@ -277,7 +274,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(weatherXml.startsWith("<"));
assertTrue(weatherXml.startsWith("<"));
}
@Test
@@ -290,7 +287,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(weatherHtml.startsWith("<"));
assertTrue(weatherHtml.startsWith("<"));
}
@Test
@@ -298,20 +295,19 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
final Weather weather = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.withValues(5, 5))
.byCoordinate(Coordinate.of(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
Assert.assertNotNull(weather);
Assert.assertNotNull(weather.getState());
Assert.assertNotNull(weather.getDescription());
Assert.assertNotNull(weather.getCalculatedOn());
Assert.assertNotNull(weather.getTemperature());
Assert.assertNotNull(weather.getLocation());
Assert.assertNotNull(weather.getAtmosphericPressure());
Assert.assertNotNull(weather.getHumidity());
Assert.assertNotNull(weather.getWind());
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
System.out.println(weather);
}
@@ -320,12 +316,12 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherJson = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.withValues(5, 5))
.byCoordinate(Coordinate.of(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJSON();
Assert.assertTrue(weatherJson.startsWith("{"));
assertTrue(weatherJson.startsWith("{"));
}
@Test
@@ -333,12 +329,12 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherXml = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.withValues(5, 5))
.byCoordinate(Coordinate.of(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asXML();
Assert.assertTrue(weatherXml.startsWith("<"));
assertTrue(weatherXml.startsWith("<"));
}
@Test
@@ -346,12 +342,12 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherHtml = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.withValues(5, 5))
.byCoordinate(Coordinate.of(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asHTML();
Assert.assertTrue(weatherHtml.startsWith("<"));
assertTrue(weatherHtml.startsWith("<"));
}
@Test
@@ -365,15 +361,14 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(weather);
Assert.assertNotNull(weather.getState());
Assert.assertNotNull(weather.getDescription());
Assert.assertNotNull(weather.getCalculatedOn());
Assert.assertNotNull(weather.getTemperature());
Assert.assertNotNull(weather.getLocation());
Assert.assertNotNull(weather.getAtmosphericPressure());
Assert.assertNotNull(weather.getHumidity());
Assert.assertNotNull(weather.getWind());
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
System.out.println(weather);
}
@@ -388,7 +383,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(weatherJson.startsWith("{"));
assertTrue(weatherJson.startsWith("{"));
}
@Test
@@ -402,7 +397,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(weatherXml.startsWith("<"));
assertTrue(weatherXml.startsWith("<"));
}
@Test
@@ -416,7 +411,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asHTML();
Assert.assertTrue(weatherHtml.startsWith("<"));
assertTrue(weatherHtml.startsWith("<"));
}
@Test
@@ -430,15 +425,14 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJava();
Assert.assertNotNull(weather);
Assert.assertNotNull(weather.getState());
Assert.assertNotNull(weather.getDescription());
Assert.assertNotNull(weather.getCalculatedOn());
Assert.assertNotNull(weather.getTemperature());
Assert.assertNotNull(weather.getLocation());
Assert.assertNotNull(weather.getAtmosphericPressure());
Assert.assertNotNull(weather.getHumidity());
Assert.assertNotNull(weather.getWind());
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
System.out.println(weather);
}
@@ -453,7 +447,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asJSON();
Assert.assertTrue(weatherJson.startsWith("{"));
assertTrue(weatherJson.startsWith("{"));
}
@Test
@@ -467,7 +461,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asXML();
Assert.assertTrue(weatherXml.startsWith("<"));
assertTrue(weatherXml.startsWith("<"));
}
@Test
@@ -481,7 +475,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieve()
.asHTML();
Assert.assertTrue(weatherHtml.startsWith("<"));
assertTrue(weatherHtml.startsWith("<"));
}
@Test
@@ -495,7 +489,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieveAsync()
.asJava();
Assert.assertNotNull(weatherFuture);
assertNotNull(weatherFuture);
System.out.println(weatherFuture.get());
}
@@ -510,7 +504,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieveAsync()
.asJSON();
Assert.assertNotNull(weatherFuture);
assertNotNull(weatherFuture);
System.out.println(weatherFuture.get());
}
@@ -525,7 +519,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieveAsync()
.asXML();
Assert.assertNotNull(weatherXmlFuture);
assertNotNull(weatherXmlFuture);
System.out.println(weatherXmlFuture.get());
}
@@ -540,28 +534,32 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.retrieveAsync()
.asHTML();
Assert.assertNotNull(weatherFuture);
assertNotNull(weatherFuture);
System.out.println(weatherFuture.get());
}
@Test(expected = InvalidAuthTokenException.class)
@Test
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
client
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.withValues(34.53, 66.74), 10)
.retrieve()
.asJSON();
assertThrows(InvalidAuthTokenException.class, () ->
client
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.of(34.53, 66.74), 10)
.retrieve()
.asJSON()
);
}
@Test(expected = NoDataFoundException.class)
@Test
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.withValues(90.00, 66.74), 10)
.retrieve()
.asJava();
assertThrows(NoDataFoundException.class, () ->
getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.of(90.00, 66.74), 10)
.retrieve()
.asJava()
);
}
}
@@ -23,17 +23,18 @@
package com.github.prominence.openweathermap.api.utils;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class RequestUtilsUnitTest {
@Test(expected = IllegalArgumentException.class)
@Test
public void whenPassInvalidUrl_thenThrowAnException() {
RequestUtils.getResponse("wrongUrl");
assertThrows(IllegalArgumentException.class, () -> RequestUtils.getResponse("wrongUrl"));
}
@Test(expected = NoDataFoundException.class)
@Test
public void whenPassUrlToNonExistingPage_thenThrowAnException() {
RequestUtils.getResponse("https://openweathermap.org/somePage");
assertThrows(NoDataFoundException.class, () -> RequestUtils.getResponse("https://openweathermap.org/somePage"));
}
}