A lot of refactoring and documentation writing.

This commit is contained in:
2021-03-26 00:48:39 +03:00
parent b301d93b39
commit 64e02cd7a8
86 changed files with 2024 additions and 740 deletions
@@ -50,18 +50,18 @@ import org.junit.Test;
public class AtmosphericPressureUnitTest {
@Test
public void whenCreatePressureWithArgs_thenValueIsSet() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(100);
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(100);
Assert.assertEquals(100, atmosphericPressure.getValue(), 0.00001);
Assert.assertEquals(0, AtmosphericPressure.forValue(0).getValue(), 0.00001);
Assert.assertEquals(100, AtmosphericPressure.forValue(100).getValue(), 0.00001);
Assert.assertEquals(55, AtmosphericPressure.forValue(55).getValue(), 0.00001);
Assert.assertEquals(0, AtmosphericPressure.withValue(0).getValue(), 0.00001);
Assert.assertEquals(100, AtmosphericPressure.withValue(100).getValue(), 0.00001);
Assert.assertEquals(55, AtmosphericPressure.withValue(55).getValue(), 0.00001);
}
@Test
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
AtmosphericPressure one = AtmosphericPressure.forValue(22);
AtmosphericPressure two = AtmosphericPressure.forValue(22);
AtmosphericPressure one = AtmosphericPressure.withValue(22);
AtmosphericPressure two = AtmosphericPressure.withValue(22);
Assert.assertTrue(one.equals(two));
Assert.assertTrue(one.equals(one));
@@ -80,17 +80,17 @@ public class AtmosphericPressureUnitTest {
@Test
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
AtmosphericPressure one = AtmosphericPressure.forValue(5);
AtmosphericPressure two = AtmosphericPressure.forValue(88);
AtmosphericPressure one = AtmosphericPressure.withValue(5);
AtmosphericPressure two = AtmosphericPressure.withValue(88);
Assert.assertFalse(one.equals(two));
Assert.assertFalse(two.equals(one));
Assert.assertFalse(one.equals(new Object()));
Assert.assertNotEquals(one.hashCode(), two.hashCode());
one = AtmosphericPressure.forValue(44);
one = AtmosphericPressure.withValue(44);
one.setSeaLevelValue(44);
two = AtmosphericPressure.forValue(44);
two = AtmosphericPressure.withValue(44);
two.setGroundLevelValue(22);
Assert.assertFalse(one.equals(two));
@@ -104,7 +104,7 @@ public class AtmosphericPressureUnitTest {
@Test
public void whenSetValidValues_thenAllIsFine() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(14);
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(14);
atmosphericPressure.setValue(0);
atmosphericPressure.setValue(15);
atmosphericPressure.setValue(100);
@@ -118,31 +118,31 @@ public class AtmosphericPressureUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final String pressureString = AtmosphericPressure.forValue(44).toString();
final String pressureString = AtmosphericPressure.withValue(44).toString();
Assert.assertNotNull(pressureString);
Assert.assertNotEquals("", pressureString);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreatePressureByConstructorWithInvalidDataNegative_thenThrowAnException() {
AtmosphericPressure.forValue(-33);
AtmosphericPressure.withValue(-33);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreatePressureAndSetInvalidDataNegative_thenThrowAnException() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(88);
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88);
atmosphericPressure.setValue(-89);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidSeaLevelPressure_thenThrowAnException() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(88);
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88);
atmosphericPressure.setSeaLevelValue(-89);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidGroundLevelPressure_thenThrowAnException() {
AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(88);
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88);
atmosphericPressure.setGroundLevelValue(-223);
}
}
@@ -50,27 +50,27 @@ import org.junit.Test;
public class CloudsUnitTest {
@Test
public void whenCreateCloudsWithValidArgs_thenValueIsSet() {
Clouds clouds = Clouds.forValue((byte) 100);
Clouds clouds = Clouds.withValue((byte) 100);
Assert.assertEquals(100, clouds.getValue());
Assert.assertEquals(0, Clouds.forValue((byte) 0).getValue());
Assert.assertEquals(100, Clouds.forValue((byte) 100).getValue());
Assert.assertEquals(55, Clouds.forValue((byte) 55).getValue());
Assert.assertEquals(0, Clouds.withValue((byte) 0).getValue());
Assert.assertEquals(100, Clouds.withValue((byte) 100).getValue());
Assert.assertEquals(55, Clouds.withValue((byte) 55).getValue());
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCloudsByConstructorWithInvalidDataAboveHundred_thenThrowAnException() {
Clouds.forValue((byte) 110);
Clouds.withValue((byte) 110);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCloudsByConstructorWithInvalidDataNegative_thenThrowAnException() {
Clouds.forValue((byte) -33);
Clouds.withValue((byte) -33);
}
@Test
public void whenSetValidValues_thenAllIsFine() {
Clouds clouds = Clouds.forValue((byte) 14);
Clouds clouds = Clouds.withValue((byte) 14);
clouds.setValue((byte) 0);
Assert.assertEquals(0, clouds.getValue());
clouds.setValue((byte) 15);
@@ -81,20 +81,20 @@ public class CloudsUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenCreateCloudsAndSetInvalidDataAboveHundred_thenThrowAnException() {
Clouds clouds = Clouds.forValue((byte) 12);
Clouds clouds = Clouds.withValue((byte) 12);
clouds.setValue((byte) 112);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCloudsAndSetInvalidDataNegative_thenThrowAnException() {
Clouds clouds = Clouds.forValue((byte) 88);
Clouds clouds = Clouds.withValue((byte) 88);
clouds.setValue((byte) -89);
}
@Test
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
Clouds one = Clouds.forValue((byte) 22);
Clouds two = Clouds.forValue((byte) 22);
Clouds one = Clouds.withValue((byte) 22);
Clouds two = Clouds.withValue((byte) 22);
Assert.assertTrue(one.equals(two));
Assert.assertTrue(one.equals(one));
@@ -103,8 +103,8 @@ public class CloudsUnitTest {
@Test
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
Clouds one = Clouds.forValue((byte) 5);
Clouds two = Clouds.forValue((byte) 88);
Clouds one = Clouds.withValue((byte) 5);
Clouds two = Clouds.withValue((byte) 88);
Assert.assertFalse(one.equals(two));
Assert.assertFalse(two.equals(one));
@@ -114,7 +114,7 @@ public class CloudsUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final String cloudsString = Clouds.forValue((byte) 44).toString();
final String cloudsString = Clouds.withValue((byte) 44).toString();
Assert.assertNotNull(cloudsString);
Assert.assertNotEquals("", cloudsString);
}
@@ -20,28 +20,6 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.model;
import org.junit.Assert;
@@ -50,52 +28,93 @@ import org.junit.Test;
public class CoordinateRectangleUnitTest {
@Test
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLatitudeBottomBelowMinus90_thenThrowAnException() {
CoordinateRectangle.forValues(44.5, -91.2, 54.4, 22.2);
CoordinateRectangle.withValues(44.5, -91.2, 54.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLatitudeBottomAbove90_thenThrowAnException() {
CoordinateRectangle.forValues(44.5, 91.2, 54.4, 22.2);
CoordinateRectangle.withValues(44.5, 91.2, 54.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLatitudeTopBelowMinus90_thenThrowAnException() {
CoordinateRectangle.forValues(44.5, 22.4, 54.4, -92.3);
CoordinateRectangle.withValues(44.5, 22.4, 54.4, -92.3);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLatitudeTopAbove90_thenThrowAnException() {
CoordinateRectangle.forValues(44.5, 22.5, 54.4, 94.887);
CoordinateRectangle.withValues(44.5, 22.5, 54.4, 94.887);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLongitudeLeftBelowMinus180_thenThrowAnException() {
CoordinateRectangle.forValues(-944.5, 22.4, 54.4, 22.2);
CoordinateRectangle.withValues(-944.5, 22.4, 54.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLongitudeLeftAbove180_thenThrowAnException() {
CoordinateRectangle.forValues(544.5, 22.4, 54.4, 22.2);
CoordinateRectangle.withValues(544.5, 22.4, 54.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLongitudeRightBelowMinus180_thenThrowAnException() {
CoordinateRectangle.forValues(44.5, 22.4, -254.4, 22.2);
CoordinateRectangle.withValues(44.5, 22.4, -254.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithLongitudeRightAbove180_thenThrowAnException() {
CoordinateRectangle.forValues(44.5, 22.4, 354.4, 22.2);
CoordinateRectangle.withValues(44.5, 22.4, 354.4, 22.2);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectUsingBuilderWithInvalidLatitudeBottom_thenFail() {
new CoordinateRectangle.Builder()
.setLatitudeBottom(-1000);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectUsingBuilderWithInvalidLatitudeTop_thenFail() {
new CoordinateRectangle.Builder()
.setLatitudeTop(-1000);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectUsingBuilderWithInvalidLongitudeLeft_thenFail() {
new CoordinateRectangle.Builder()
.setLongitudeLeft(-1000);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectUsingBuilderWithInvalidLongitudeRight_thenFail() {
new CoordinateRectangle.Builder()
.setLongitudeRight(-1000);
}
@Test(expected = IllegalStateException.class)
public void whenCreateObjectUsingBuilderWithoutAllPropertiesSet_thenFail() {
new CoordinateRectangle.Builder()
.setLongitudeRight(10)
.build();
}
@Test
public void whenCreateObjectUsingBuilderWithCorrectUsage_thenOk() {
new CoordinateRectangle.Builder()
.setLongitudeRight(10)
.setLongitudeLeft(10)
.setLatitudeTop(10)
.setLatitudeBottom(10)
.build();
}
@Test
public void whenGetAllParameters_thenAllIsFine() {
final CoordinateRectangle rectangle = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
final CoordinateRectangle rectangle = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
Assert.assertEquals(44.5, rectangle.getLongitudeLeft(), 0.00001);
Assert.assertEquals(22.4, rectangle.getLatitudeBottom(), 0.00001);
Assert.assertEquals(54.4, rectangle.getLongitudeRight(), 0.00001);
@@ -104,7 +123,7 @@ public class CoordinateRectangleUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final CoordinateRectangle rectangle = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
final CoordinateRectangle rectangle = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
Assert.assertNotNull(rectangle.toString());
Assert.assertNotEquals("", rectangle.toString());
@@ -112,12 +131,12 @@ public class CoordinateRectangleUnitTest {
@Test
public void whenCallHashCode_thenAllIsFine() {
final CoordinateRectangle first = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
final CoordinateRectangle second = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
final CoordinateRectangle first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
final CoordinateRectangle second = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
Assert.assertEquals(first.hashCode(), second.hashCode());
final CoordinateRectangle third = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 23.566);
final CoordinateRectangle third = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 23.566);
Assert.assertNotEquals(first.hashCode(), third.hashCode());
Assert.assertNotEquals(second.hashCode(), third.hashCode());
@@ -125,26 +144,26 @@ public class CoordinateRectangleUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
CoordinateRectangle first = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
CoordinateRectangle second = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2);
CoordinateRectangle first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
CoordinateRectangle second = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
Assert.assertFalse(first.equals(new Object()));
first = CoordinateRectangle.forValues(49.5, 22.4, 54.4, 22.2);
first = CoordinateRectangle.withValues(49.5, 22.4, 54.4, 22.2);
Assert.assertFalse(first.equals(second));
first = CoordinateRectangle.forValues(44.5, 29.4, 54.4, 22.2);
first = CoordinateRectangle.withValues(44.5, 29.4, 54.4, 22.2);
Assert.assertFalse(first.equals(second));
first = CoordinateRectangle.forValues(44.5, 22.4, 24.4, 22.2);
first = CoordinateRectangle.withValues(44.5, 22.4, 24.4, 22.2);
Assert.assertFalse(first.equals(second));
first = CoordinateRectangle.forValues(44.5, 22.4, 54.4, -2.2);
first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, -2.2);
Assert.assertFalse(first.equals(second));
}
@@ -20,28 +20,6 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.model;
import org.junit.Assert;
@@ -50,32 +28,32 @@ import org.junit.Test;
public class CoordinateUnitTest {
@Test
public void whenCreateCoordinateWithValidValues_thenObjectCreated() {
Coordinate.forValues(44, 53);
Coordinate.withValues(44, 53);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCoordinateWithInvalidLatitudeBelowMinus90_thenThrowAnException() {
Coordinate.forValues(-333, 44);
Coordinate.withValues(-333, 44);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCoordinateWithInvalidLatitudeAbove90_thenThrowAnException() {
Coordinate.forValues(223, 44);
Coordinate.withValues(223, 44);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCoordinateWithInvalidLongitudeBelowMinus180_thenThrowAnException() {
Coordinate.forValues(33, -999);
Coordinate.withValues(33, -999);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateCoordinateWithInvalidLongitudeAbove180_thenThrowAnException() {
Coordinate.forValues(33, 999);
Coordinate.withValues(33, 999);
}
@Test
public void whenSetValidCoordinates_thenAllIsFine() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLatitude(-90);
Assert.assertEquals(-90, coordinate.getLatitude(), 0.00001);
@@ -94,31 +72,31 @@ public class CoordinateUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidLatitudeBelowMinus90_thenThrowAnException() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLatitude(-91);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidLatitudeAbove90_thenThrowAnException() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLatitude(92);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidLongitudeBelowMinus180_thenThrowAnException() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLongitude(-194);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidLongitudeAbove180_thenThrowAnException() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
coordinate.setLongitude(444);
}
@Test
public void whenGetLatitude_thenAllIsFine() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
Assert.assertEquals(0, coordinate.getLatitude(), 0.00001);
coordinate.setLatitude(45);
@@ -128,7 +106,7 @@ public class CoordinateUnitTest {
@Test
public void whenGetLongitude_thenAllIsFine() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
Assert.assertEquals(0, coordinate.getLongitude(), 0.00001);
coordinate.setLongitude(33);
@@ -138,15 +116,15 @@ public class CoordinateUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final Coordinate coordinate = Coordinate.forValues(0, 0);
final Coordinate coordinate = Coordinate.withValues(0, 0);
Assert.assertNotNull(coordinate.toString());
Assert.assertNotEquals("", coordinate.toString());
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final Coordinate first = Coordinate.forValues(22, 66);
final Coordinate second = Coordinate.forValues(22, 44);
final Coordinate first = Coordinate.withValues(22, 66);
final Coordinate second = Coordinate.withValues(22, 44);
Assert.assertNotEquals(first.hashCode(), second.hashCode());
@@ -165,8 +143,8 @@ public class CoordinateUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Coordinate first = Coordinate.forValues(11, 99);
final Coordinate second = Coordinate.forValues(11, 99);
final Coordinate first = Coordinate.withValues(11, 99);
final Coordinate second = Coordinate.withValues(11, 99);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
@@ -20,28 +20,6 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.model;
import org.junit.Assert;
@@ -50,26 +28,26 @@ import org.junit.Test;
public class HumidityUnitTest {
@Test
public void whenCreateHumidityWithArgs_thenValueIsSet() {
Humidity humidity = Humidity.forValue((byte) 100);
Humidity humidity = Humidity.withValue((byte) 100);
Assert.assertEquals(100, humidity.getValue());
Assert.assertEquals(0, Humidity.forValue((byte) 0).getValue());
Assert.assertEquals(55, Humidity.forValue((byte) 55).getValue());
Assert.assertEquals(0, Humidity.withValue((byte) 0).getValue());
Assert.assertEquals(55, Humidity.withValue((byte) 55).getValue());
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateHumidityByConstructorWithInvalidDataAboveHundred_thenThrowAnException() {
Humidity.forValue((byte) 112);
Humidity.withValue((byte) 112);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateHumidityByConstructorWithInvalidDataNegative_thenThrowAnException() {
Humidity.forValue((byte) -33);
Humidity.withValue((byte) -33);
}
@Test
public void whenSetValidValues_thenAllIsFine() {
Humidity humidity = Humidity.forValue((byte) 14);
Humidity humidity = Humidity.withValue((byte) 14);
Assert.assertEquals(14, humidity.getValue());
humidity.setValue((byte) 0);
Assert.assertEquals(0, humidity.getValue());
@@ -81,20 +59,20 @@ public class HumidityUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenCreateHumidityAndSetInvalidDataAboveHundred_thenThrowAnException() {
Humidity humidity = Humidity.forValue((byte) 12);
Humidity humidity = Humidity.withValue((byte) 12);
humidity.setValue((byte) 112);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateHumidityAndSetInvalidDataNegative_thenThrowAnException() {
Humidity humidity = Humidity.forValue((byte) 88);
Humidity humidity = Humidity.withValue((byte) 88);
humidity.setValue((byte) -89);
}
@Test
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
Humidity one = Humidity.forValue((byte) 22);
Humidity two = Humidity.forValue((byte) 22);
Humidity one = Humidity.withValue((byte) 22);
Humidity two = Humidity.withValue((byte) 22);
Assert.assertTrue(one.equals(two));
Assert.assertTrue(one.equals(one));
@@ -103,8 +81,8 @@ public class HumidityUnitTest {
@Test
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
Humidity one = Humidity.forValue((byte) 5);
Humidity two = Humidity.forValue((byte) 88);
Humidity one = Humidity.withValue((byte) 5);
Humidity two = Humidity.withValue((byte) 88);
Assert.assertFalse(one.equals(two));
Assert.assertFalse(two.equals(one));
@@ -114,7 +92,7 @@ public class HumidityUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final String humidityString = Humidity.forValue((byte) 44).toString();
final String humidityString = Humidity.withValue((byte) 44).toString();
Assert.assertNotNull(humidityString);
Assert.assertNotEquals("", humidityString);
}
@@ -20,28 +20,6 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.model;
import org.junit.Assert;
@@ -50,17 +28,17 @@ import org.junit.Test;
public class TemperatureUnitTest {
@Test
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
Temperature.forValue(22.2, "K");
Temperature.withValue(22.2, "K");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithEmptyUnit_thenThrowAnException() {
Temperature.forValue(22.2, null);
Temperature.withValue(22.2, null);
}
@Test
public void whenSetValue_thenAllIsFine() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setValue(55.44);
Assert.assertEquals(55.44, temperature.getValue(), 0.00001);
@@ -68,7 +46,7 @@ public class TemperatureUnitTest {
@Test
public void whenSetMaximumTemperature_thenAllIsOk() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setMaxTemperature(44.4);
Assert.assertEquals(44.4, temperature.getMaxTemperature(), 0.00001);
@@ -80,7 +58,7 @@ public class TemperatureUnitTest {
@Test
public void whenSetMinimumTemperature_thenAllIsOk() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setMinTemperature(33.2);
Assert.assertEquals(33.2, temperature.getMinTemperature(), 0.00001);
@@ -92,7 +70,7 @@ public class TemperatureUnitTest {
@Test
public void whenSetFeelsLikeTemperature_thenAllIsOk() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setFeelsLike(22.3);
Assert.assertEquals(22.3, temperature.getFeelsLike(), 0.00001);
@@ -104,7 +82,7 @@ public class TemperatureUnitTest {
@Test
public void whenSetNonNullUnit_thenAllIsOk() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setUnit("test");
Assert.assertTrue("test".equals(temperature.getUnit()));
@@ -112,14 +90,14 @@ public class TemperatureUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetNullUnit_thenThrowAnException() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
temperature.setUnit(null);
}
@Test
public void whenCallToString_thenAllIsFine() {
final Temperature temperature = Temperature.forValue(22.2, "K");
final Temperature temperature = Temperature.withValue(22.2, "K");
Assert.assertNotNull(temperature.toString());
Assert.assertNotEquals("", temperature.toString());
@@ -142,16 +120,16 @@ public class TemperatureUnitTest {
@Test
public void whenCallHashCode_thenAllIsFine() {
final Temperature one = Temperature.forValue(22.2, "K");
final Temperature two = Temperature.forValue(22.2, "K");
final Temperature one = Temperature.withValue(22.2, "K");
final Temperature two = Temperature.withValue(22.2, "K");
Assert.assertEquals(one.hashCode(), two.hashCode());
}
@Test
public void whenCheckEquality_thenAllIsFine() {
final Temperature one = Temperature.forValue(22.2, "K");
final Temperature two = Temperature.forValue(21.2, "K");
final Temperature one = Temperature.withValue(22.2, "K");
final Temperature two = Temperature.withValue(21.2, "K");
Assert.assertTrue(one.equals(one));
Assert.assertFalse(one.equals(new Object()));
@@ -31,7 +31,7 @@ public class ForecastUnitTest {
@Test
public void whenLocationIsSet_thenAllIsOk() {
final Forecast forecast = new Forecast();
forecast.setLocation(Location.forValue(2, "asd"));
forecast.setLocation(Location.withValues(2, "asd"));
Assert.assertNotNull(forecast.getLocation());
}
@@ -51,7 +51,7 @@ public class ForecastUnitTest {
Assert.assertEquals(one.hashCode(), two.hashCode());
one.setLocation(Location.forValue(22, "444"));
one.setLocation(Location.withValues(22, "444"));
Assert.assertNotEquals(one.hashCode(), two.hashCode());
}
@@ -66,7 +66,7 @@ public class ForecastUnitTest {
Assert.assertTrue(one.equals(two));
Assert.assertFalse(one.equals(new Object()));
one.setLocation(Location.forValue(22, "234"));
one.setLocation(Location.withValues(22, "234"));
Assert.assertFalse(one.equals(two));
@@ -32,17 +32,17 @@ import java.time.ZoneOffset;
public class LocationUnitTest {
@Test
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
Location.forValue(33, "test");
Location.withValues(33, "test");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithoutName_thenThrowAnException() {
Location.forValue(33, null);
Location.withValues(33, null);
}
@Test
public void whenSetId_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setId(55);
Assert.assertEquals(55, location.getId());
@@ -50,7 +50,7 @@ public class LocationUnitTest {
@Test
public void whenSetName_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setName("city");
Assert.assertEquals("city", location.getName());
@@ -58,7 +58,7 @@ public class LocationUnitTest {
@Test
public void whenSetCountryCode_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setCountryCode("by");
Assert.assertEquals("by", location.getCountryCode());
@@ -66,7 +66,7 @@ public class LocationUnitTest {
@Test
public void whenSetSunrise_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
final LocalDateTime now = LocalDateTime.now();
location.setSunrise(now);
@@ -75,7 +75,7 @@ public class LocationUnitTest {
@Test
public void whenSetSunset_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
final LocalDateTime now = LocalDateTime.now();
location.setSunset(now);
@@ -84,7 +84,7 @@ public class LocationUnitTest {
@Test
public void whenSetZoneOffset_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
final ZoneOffset offset = ZoneOffset.UTC;
location.setZoneOffset(offset);
@@ -93,8 +93,8 @@ public class LocationUnitTest {
@Test
public void whenSetCoordinate_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Coordinate coordinate = Coordinate.forValues(33.2, 64.2);
final Location location = Location.withValues(33, "test");
final Coordinate coordinate = Coordinate.withValues(33.2, 64.2);
location.setCoordinate(coordinate);
Assert.assertEquals(coordinate, location.getCoordinate());
@@ -102,7 +102,7 @@ public class LocationUnitTest {
@Test
public void whenSetPopulation_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setPopulation(3444L);
Assert.assertEquals(3444L, location.getPopulation().longValue());
@@ -110,11 +110,11 @@ public class LocationUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final Location location = Location.forValue(44, "test");
final Location location = Location.withValues(44, "test");
Assert.assertNotEquals("", location.toString());
location.setCoordinate(Coordinate.forValues(33.2, 56.3));
location.setCoordinate(Coordinate.withValues(33.2, 56.3));
Assert.assertNotEquals("", location.toString());
@@ -130,8 +130,8 @@ public class LocationUnitTest {
@Test
public void whenCallHashCode_thenAllIsFine() {
final Location one = Location.forValue(44, "test");
final Location two = Location.forValue(44, "test");
final Location one = Location.withValues(44, "test");
final Location two = Location.withValues(44, "test");
Assert.assertEquals(one.hashCode(), two.hashCode());
@@ -142,8 +142,8 @@ public class LocationUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Location one = Location.forValue(44, "test");
final Location two = Location.forValue(44, "test");
final Location one = Location.withValues(44, "test");
final Location two = Location.withValues(44, "test");
Assert.assertTrue(one.equals(one));
Assert.assertFalse(one.equals(new Object()));
@@ -200,7 +200,7 @@ public class LocationUnitTest {
Assert.assertTrue(one.equals(two));
final Coordinate coordinate = Coordinate.forValues(33.5, -22.4);
final Coordinate coordinate = Coordinate.withValues(33.5, -22.4);
one.setCoordinate(coordinate);
@@ -28,42 +28,44 @@ import org.junit.Test;
public class RainUnitTest {
@Test
public void whenCreateRainWithValidArgs_thenObjectIsCreated() {
new Rain(2222.3);
new Rain(null);
Rain.withThreeHourLevelValue(2222.3);
Rain.withThreeHourLevelValue(0);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateWithInvalidData_thenFail() {
Rain.withThreeHourLevelValue(-20);
}
@Test
public void whenSetValues_thenTheyAreSet() {
final Rain rain = new Rain(null);
final Rain rain = Rain.withThreeHourLevelValue(0);
Assert.assertNull(rain.getThreeHourRainLevel());
Assert.assertEquals(0, rain.getThreeHourRainLevel(), 0.00001);
rain.setThreeHourRainLevel(55.5);
Assert.assertEquals(55.5, rain.getThreeHourRainLevel(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidValue_thenFail() {
final Rain rain = Rain.withThreeHourLevelValue(0);
rain.setThreeHourRainLevel(-20);
}
@Test
public void whenCallToString_thenAllIsFine() {
final Rain rain = new Rain();
final Rain rain = Rain.withThreeHourLevelValue(33.5);
Assert.assertNotNull(rain.toString());
Assert.assertEquals("unknown", rain.toString());
rain.setThreeHourRainLevel(33.5);
Assert.assertNotNull(rain.toString());
Assert.assertNotEquals("unknown", rain.toString());
rain.setThreeHourRainLevel(null);
Assert.assertNotNull(rain.toString());
Assert.assertEquals("unknown", rain.toString());
Assert.assertNotEquals("", rain.toString());
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final Rain first = new Rain();
final Rain second = new Rain();
final Rain first = Rain.withThreeHourLevelValue(0);
final Rain second = Rain.withThreeHourLevelValue(0);
Assert.assertEquals(first.hashCode(), second.hashCode());
@@ -78,8 +80,8 @@ public class RainUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Rain first = new Rain();
final Rain second = new Rain();
final Rain first = Rain.withThreeHourLevelValue(0);
final Rain second = Rain.withThreeHourLevelValue(0);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
@@ -28,42 +28,43 @@ import org.junit.Test;
public class SnowUnitTest {
@Test
public void whenCreateSnowWithValidArgs_ObjectIsCreated() {
new Snow(2222.3);
new Snow(null);
Snow.withThreeHourLevelValue(2222.3);
Snow.withThreeHourLevelValue(0);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateWithInvalidData_thenFail() {
Snow.withThreeHourLevelValue(-20);
}
@Test
public void whenSetValues_thenTheyAreSet() {
final Snow snow = new Snow(null);
final Snow snow = Snow.withThreeHourLevelValue(0);
Assert.assertNull(snow.getThreeHourSnowLevel());
Assert.assertEquals(0, snow.getThreeHourSnowLevel(), 0.00001);
snow.setThreeHourSnowLevel(55.5);
Assert.assertEquals(55.5, snow.getThreeHourSnowLevel(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidValue_thenFail() {
final Snow snow = Snow.withThreeHourLevelValue(0);
snow.setThreeHourSnowLevel(-20);
}
@Test
public void whenCallToString_thenAllIsFine() {
final Snow snow = new Snow();
final Snow snow = Snow.withThreeHourLevelValue(33.5);
Assert.assertNotNull(snow.toString());
Assert.assertEquals("unknown", snow.toString());
snow.setThreeHourSnowLevel(33.5);
Assert.assertNotNull(snow.toString());
Assert.assertNotEquals("unknown", snow.toString());
snow.setThreeHourSnowLevel(null);
Assert.assertNotNull(snow.toString());
Assert.assertEquals("unknown", snow.toString());
Assert.assertNotEquals("", snow.toString());
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final Snow first = new Snow();
final Snow second = new Snow();
final Snow first = Snow.withThreeHourLevelValue(0);
final Snow second = Snow.withThreeHourLevelValue(0);
Assert.assertEquals(first.hashCode(), second.hashCode());
@@ -78,8 +79,8 @@ public class SnowUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Snow first = new Snow();
final Snow second = new Snow();
final Snow first = Snow.withThreeHourLevelValue(0);
final Snow second = Snow.withThreeHourLevelValue(0);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
@@ -20,28 +20,6 @@
* SOFTWARE.
*/
/*
* Copyright (c) 2021 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.model.forecast;
import com.github.prominence.openweathermap.api.model.*;
@@ -114,7 +92,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetTemperature_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Temperature temperature = Temperature.forValue(22.3, "a");
final Temperature temperature = Temperature.withValue(22.3, "a");
weatherForecast.setTemperature(temperature);
Assert.assertEquals(temperature, weatherForecast.getTemperature());
@@ -123,7 +101,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetPressure_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(33.2);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.2);
weatherForecast.setAtmosphericPressure(atmosphericPressure);
Assert.assertEquals(atmosphericPressure, weatherForecast.getAtmosphericPressure());
@@ -132,7 +110,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetHumidity_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Humidity humidity = Humidity.forValue((byte) 44);
final Humidity humidity = Humidity.withValue((byte) 44);
weatherForecast.setHumidity(humidity);
Assert.assertEquals(humidity, weatherForecast.getHumidity());
@@ -141,7 +119,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetWind_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Wind wind = Wind.forValue(22.2, "a");
final Wind wind = Wind.withValue(22.2, "a");
weatherForecast.setWind(wind);
Assert.assertEquals(wind, weatherForecast.getWind());
@@ -150,7 +128,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetRain_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Rain rain = new Rain();
final Rain rain = Rain.withThreeHourLevelValue(0);
weatherForecast.setRain(rain);
Assert.assertEquals(rain, weatherForecast.getRain());
@@ -159,7 +137,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetSnow_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Snow snow = new Snow();
final Snow snow = Snow.withThreeHourLevelValue(0);
weatherForecast.setSnow(snow);
Assert.assertEquals(snow, weatherForecast.getSnow());
@@ -168,7 +146,7 @@ public class WeatherForecastUnitTest {
@Test
public void whenSetClouds_thenValueIsSet() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Clouds clouds = Clouds.forValue((byte) 33);
final Clouds clouds = Clouds.withValue((byte) 33);
weatherForecast.setClouds(clouds);
Assert.assertEquals(clouds, weatherForecast.getClouds());
@@ -199,12 +177,12 @@ public class WeatherForecastUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
final Location location = Location.forValue(12312, "asd");
final Temperature temperature = Temperature.forValue(33.2, "asd");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(44.4);
final Clouds clouds = Clouds.forValue((byte) 55);
final Rain rain = new Rain(33.2);
final Snow snow = new Snow(33.1);
final Location location = Location.withValues(12312, "asd");
final Temperature temperature = Temperature.withValue(33.2, "asd");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(44.4);
final Clouds clouds = Clouds.withValue((byte) 55);
final Rain rain = Rain.withThreeHourLevelValue(33.2);
final Snow snow = Snow.withThreeHourLevelValue(33.1);
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
@@ -241,11 +219,11 @@ public class WeatherForecastUnitTest {
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
weatherForecast.setRain(new Rain(null));
weatherForecast.setRain(Rain.withThreeHourLevelValue(0));
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
weatherForecast.setSnow(new Snow(null));
weatherForecast.setSnow(Snow.withThreeHourLevelValue(0));
Assert.assertNotEquals("", weatherForecast.toString());
Assert.assertNotNull(weatherForecast.toString());
}
@@ -297,7 +275,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final Temperature temperature = Temperature.forValue(33.2, "as");
final Temperature temperature = Temperature.withValue(33.2, "as");
one.setTemperature(temperature);
Assert.assertFalse(one.equals(two));
@@ -306,7 +284,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(33.33);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.33);
one.setAtmosphericPressure(atmosphericPressure);
Assert.assertFalse(one.equals(two));
@@ -315,7 +293,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final Humidity humidity = Humidity.forValue((byte) 33);
final Humidity humidity = Humidity.withValue((byte) 33);
one.setHumidity(humidity);
Assert.assertFalse(one.equals(two));
@@ -324,7 +302,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final Wind wind = Wind.forValue(33.6, "asd");
final Wind wind = Wind.withValue(33.6, "asd");
one.setWind(wind);
Assert.assertFalse(one.equals(two));
@@ -333,7 +311,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final Rain rain = new Rain();
final Rain rain = Rain.withThreeHourLevelValue(0);
one.setRain(rain);
Assert.assertFalse(one.equals(two));
@@ -342,7 +320,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final Snow snow = new Snow();
final Snow snow = Snow.withThreeHourLevelValue(0);
one.setSnow(snow);
Assert.assertFalse(one.equals(two));
@@ -351,7 +329,7 @@ public class WeatherForecastUnitTest {
Assert.assertTrue(one.equals(two));
final Clouds clouds = Clouds.forValue((byte) 33);
final Clouds clouds = Clouds.withValue((byte) 33);
one.setClouds(clouds);
Assert.assertFalse(one.equals(two));
@@ -28,22 +28,22 @@ import org.junit.Test;
public class WindUnitTest {
@Test
public void whenCreateWindWithValidArgs_thenValueIsSet() {
Assert.assertEquals(44.0, Wind.forValue(44, "ms").getSpeed(), 0.00001);
Assert.assertEquals(44.0, Wind.withValue(44, "ms").getSpeed(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateWindWithInvalidSpeedArg_thenThrowAnException() {
Wind.forValue(-21, "a");
Wind.withValue(-21, "a");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateWindWithInvalidUnitArg_thenThrowAnException() {
Wind.forValue(342, null);
Wind.withValue(342, null);
}
@Test
public void whenSetValidSpeed_thenValueIsSet() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
@@ -58,7 +58,7 @@ public class WindUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidSpeedBelow0_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
@@ -67,7 +67,7 @@ public class WindUnitTest {
@Test
public void whenSetValidDegrees_thenValueIsSet() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertNull(wind.getDegrees());
@@ -86,19 +86,19 @@ public class WindUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidDegreesBelow0_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setDegrees(-32);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidDegreesAbove360_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setDegrees(378);
}
@Test
public void whenSetNonNullUnit_thenValueIsSet() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(wind.getUnit(), "as");
@@ -109,14 +109,14 @@ public class WindUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetNullUnit_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setUnit(null);
}
@Test
public void whenCallToString_thenAllIsFine() {
final Wind wind = Wind.forValue(302, "a");
final Wind wind = Wind.withValue(302, "a");
Assert.assertNotNull(wind.toString());
@@ -128,8 +128,8 @@ public class WindUnitTest {
@Test
public void whenCallHashCode_thenAllIsFine() {
final Wind first = Wind.forValue(22, "a");
final Wind second = Wind.forValue(22, "b");
final Wind first = Wind.withValue(22, "a");
final Wind second = Wind.withValue(22, "b");
Assert.assertNotEquals(first.hashCode(), second.hashCode());
@@ -152,8 +152,8 @@ public class WindUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Wind first = Wind.forValue(11, "a");
final Wind second = Wind.forValue(11, "a");
final Wind first = Wind.withValue(11, "a");
final Wind second = Wind.withValue(11, "a");
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
@@ -32,17 +32,17 @@ import java.time.ZoneOffset;
public class LocationUnitTest {
@Test
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
Location.forValue(33, "test");
Location.withValues(33, "test");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateObjectWithoutName_thenThrowAnException() {
Location.forValue(33, null);
Location.withValues(33, null);
}
@Test
public void whenSetId_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setId(55);
Assert.assertEquals(55, location.getId());
@@ -50,7 +50,7 @@ public class LocationUnitTest {
@Test
public void whenSetName_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setName("city");
Assert.assertEquals("city", location.getName());
@@ -58,7 +58,7 @@ public class LocationUnitTest {
@Test
public void whenSetCountryCode_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
location.setCountryCode("by");
Assert.assertEquals("by", location.getCountryCode());
@@ -66,7 +66,7 @@ public class LocationUnitTest {
@Test
public void whenSetSunrise_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
final LocalDateTime now = LocalDateTime.now();
location.setSunrise(now);
@@ -75,7 +75,7 @@ public class LocationUnitTest {
@Test
public void whenSetSunset_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
final LocalDateTime now = LocalDateTime.now();
location.setSunset(now);
@@ -84,7 +84,7 @@ public class LocationUnitTest {
@Test
public void whenSetZoneOffset_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Location location = Location.withValues(33, "test");
final ZoneOffset offset = ZoneOffset.UTC;
location.setZoneOffset(offset);
@@ -93,8 +93,8 @@ public class LocationUnitTest {
@Test
public void whenSetCoordinate_thenValueIsSet() {
final Location location = Location.forValue(33, "test");
final Coordinate coordinate = Coordinate.forValues(33.2, 64.2);
final Location location = Location.withValues(33, "test");
final Coordinate coordinate = Coordinate.withValues(33.2, 64.2);
location.setCoordinate(coordinate);
Assert.assertEquals(coordinate, location.getCoordinate());
@@ -102,11 +102,11 @@ public class LocationUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final Location location = Location.forValue(44, "test");
final Location location = Location.withValues(44, "test");
Assert.assertNotEquals("", location.toString());
location.setCoordinate(Coordinate.forValues(33.2, 56.3));
location.setCoordinate(Coordinate.withValues(33.2, 56.3));
Assert.assertNotEquals("", location.toString());
@@ -118,8 +118,8 @@ public class LocationUnitTest {
@Test
public void whenCallHashCode_thenAllIsFine() {
final Location one = Location.forValue(44, "test");
final Location two = Location.forValue(44, "test");
final Location one = Location.withValues(44, "test");
final Location two = Location.withValues(44, "test");
Assert.assertEquals(one.hashCode(), two.hashCode());
@@ -130,8 +130,8 @@ public class LocationUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Location one = Location.forValue(44, "test");
final Location two = Location.forValue(44, "test");
final Location one = Location.withValues(44, "test");
final Location two = Location.withValues(44, "test");
Assert.assertTrue(one.equals(one));
Assert.assertFalse(one.equals(new Object()));
@@ -188,7 +188,7 @@ public class LocationUnitTest {
Assert.assertTrue(one.equals(two));
final Coordinate coordinate = Coordinate.forValues(33.5, -22.4);
final Coordinate coordinate = Coordinate.withValues(33.5, -22.4);
one.setCoordinate(coordinate);
@@ -28,18 +28,14 @@ import org.junit.Test;
public class RainUnitTest {
@Test
public void whenCreateRainWithValidArgs_thenObjectIsCreated() {
new Rain(2222.3, 324234.3);
new Rain(null, -213123.4);
new Rain(-123123.123, null);
new Rain(null, null);
Rain.withValues(2222.3, 324234.3);
Rain.withThreeHourLevelValue(213123.4);
Rain.withOneHourLevelValue(123123.123);
}
@Test
public void whenSetValues_thenTheyAreSet() {
final Rain rain = new Rain(null, null);
Assert.assertNull(rain.getOneHourRainLevel());
Assert.assertNull(rain.getThreeHourRainLevel());
final Rain rain = Rain.withValues(0, 0);
rain.setOneHourRainLevel(33.3);
Assert.assertEquals(33.3, rain.getOneHourRainLevel(), 0.00001);
@@ -50,31 +46,33 @@ public class RainUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final Rain rain = new Rain();
Rain rain = Rain.withThreeHourLevelValue(33.5);
Assert.assertNotNull(rain.toString());
Assert.assertEquals("unknown", rain.toString());
rain.setThreeHourRainLevel(33.5);
Assert.assertNotNull(rain.toString());
Assert.assertNotEquals("unknown", rain.toString());
Assert.assertNotEquals("", rain.toString());
rain.setOneHourRainLevel(22.2);
Assert.assertNotNull(rain.toString());
Assert.assertNotEquals("unknown", rain.toString());
Assert.assertNotEquals("", rain.toString());
}
rain.setThreeHourRainLevel(null);
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidOneHourLevelValue_thenFail() {
final Rain rain = Rain.withValues(0, 0);
rain.setOneHourRainLevel(-20);
}
Assert.assertNotNull(rain.toString());
Assert.assertNotEquals("unknown", rain.toString());
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidThreeHourLevelValue_thenFail() {
final Rain rain = Rain.withValues(0, 0);
rain.setThreeHourRainLevel(-20);
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final Rain first = new Rain();
final Rain second = new Rain();
final Rain first = Rain.withValues(0, 0);
final Rain second = Rain.withValues(0, 0);
Assert.assertEquals(first.hashCode(), second.hashCode());
@@ -97,8 +95,8 @@ public class RainUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Rain first = new Rain();
final Rain second = new Rain();
final Rain first = Rain.withValues(0, 0);
final Rain second = Rain.withValues(0, 0);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
@@ -28,18 +28,14 @@ import org.junit.Test;
public class SnowUnitTest {
@Test
public void whenCreateSnowWithValidArgs_ObjectIsCreated() {
new Snow(2222.3, 324234.3);
new Snow(null, -213123.4);
new Snow(-123123.123, null);
new Snow(null, null);
Snow.withValues(2222.3, 324234.3);
Snow.withThreeHourLevelValue(213123.4);
Snow.withOneHourLevelValue(123123.123);
}
@Test
public void whenSetValues_thenTheyAreSet() {
final Snow snow = new Snow(null, null);
Assert.assertNull(snow.getOneHourSnowLevel());
Assert.assertNull(snow.getThreeHourSnowLevel());
final Snow snow = Snow.withValues(0, 0);
snow.setOneHourSnowLevel(33.3);
Assert.assertEquals(33.3, snow.getOneHourSnowLevel(), 0.00001);
@@ -48,33 +44,40 @@ public class SnowUnitTest {
Assert.assertEquals(55.5, snow.getThreeHourSnowLevel(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidOneHourLevelValue_thenFail() {
final Snow rain = Snow.withValues(0, 0);
rain.setOneHourSnowLevel(-20);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidThreeHourLevelValue_thenFail() {
final Snow rain = Snow.withValues(0, 0);
rain.setThreeHourSnowLevel(-20);
}
@Test
public void whenCallToString_thenAllIsFine() {
final Snow snow = new Snow();
final Snow snow = Snow.withOneHourLevelValue(33.5);
Assert.assertNotNull(snow.toString());
Assert.assertEquals("unknown", snow.toString());
snow.setThreeHourSnowLevel(33.5);
Assert.assertNotNull(snow.toString());
Assert.assertNotEquals("unknown", snow.toString());
Assert.assertNotEquals("", snow.toString());
snow.setOneHourSnowLevel(22.2);
Assert.assertNotNull(snow.toString());
Assert.assertNotEquals("unknown", snow.toString());
Assert.assertNotEquals("", snow.toString());
snow.setThreeHourSnowLevel(null);
snow.setThreeHourSnowLevel(33.2);
Assert.assertNotNull(snow.toString());
Assert.assertNotEquals("unknown", snow.toString());
Assert.assertNotEquals("", snow.toString());
}
@Test
public void whenCallHashCode_thenAllIsFine() {
final Snow first = new Snow();
final Snow second = new Snow();
final Snow first = Snow.withValues(0, 0);
final Snow second = Snow.withValues(0, 0);
Assert.assertEquals(first.hashCode(), second.hashCode());
@@ -97,8 +100,8 @@ public class SnowUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Snow first = new Snow();
final Snow second = new Snow();
final Snow first = Snow.withValues(0, 0);
final Snow second = Snow.withValues(0, 0);
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
@@ -95,7 +95,7 @@ public class WeatherUnitTest {
@Test
public void whenSetTemperature_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Temperature temperature = Temperature.forValue(22.3, "a");
final Temperature temperature = Temperature.withValue(22.3, "a");
weather.setTemperature(temperature);
Assert.assertEquals(temperature, weather.getTemperature());
@@ -104,7 +104,7 @@ public class WeatherUnitTest {
@Test
public void whenSetPressure_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(33.2);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.2);
weather.setAtmosphericPressure(atmosphericPressure);
Assert.assertEquals(atmosphericPressure, weather.getAtmosphericPressure());
@@ -113,7 +113,7 @@ public class WeatherUnitTest {
@Test
public void whenSetHumidity_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Humidity humidity = Humidity.forValue((byte) 44);
final Humidity humidity = Humidity.withValue((byte) 44);
weather.setHumidity(humidity);
Assert.assertEquals(humidity, weather.getHumidity());
@@ -122,7 +122,7 @@ public class WeatherUnitTest {
@Test
public void whenSetWind_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Wind wind = Wind.forValue(22.2, "a");
final Wind wind = Wind.withValue(22.2, "a");
weather.setWind(wind);
Assert.assertEquals(wind, weather.getWind());
@@ -131,7 +131,7 @@ public class WeatherUnitTest {
@Test
public void whenSetRain_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Rain rain = new Rain();
final Rain rain = Rain.withValues(0, 0);
weather.setRain(rain);
Assert.assertEquals(rain, weather.getRain());
@@ -140,7 +140,7 @@ public class WeatherUnitTest {
@Test
public void whenSetSnow_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Snow snow = new Snow();
final Snow snow = Snow.withValues(0, 0);
weather.setSnow(snow);
Assert.assertEquals(snow, weather.getSnow());
@@ -149,7 +149,7 @@ public class WeatherUnitTest {
@Test
public void whenSetClouds_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Clouds clouds = Clouds.forValue((byte) 33);
final Clouds clouds = Clouds.withValue((byte) 33);
weather.setClouds(clouds);
Assert.assertEquals(clouds, weather.getClouds());
@@ -158,7 +158,7 @@ public class WeatherUnitTest {
@Test
public void whenSetLocation_thenValueIsSet() {
final Weather weather = Weather.forValue("state", "desc");
final Location location = Location.forValue(22, "asd");
final Location location = Location.withValues(22, "asd");
weather.setLocation(location);
Assert.assertEquals(location, weather.getLocation());
@@ -167,12 +167,12 @@ public class WeatherUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final Weather weather = Weather.forValue("state", "desc");
final Location location = Location.forValue(12312, "asd");
final Temperature temperature = Temperature.forValue(33.2, "asd");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(44.4);
final Clouds clouds = Clouds.forValue((byte) 55);
final Rain rain = new Rain(33.2, null);
final Snow snow = new Snow(33.1, null);
final Location location = Location.withValues(12312, "asd");
final Temperature temperature = Temperature.withValue(33.2, "asd");
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(44.4);
final Clouds clouds = Clouds.withValue((byte) 55);
final Rain rain = Rain.withOneHourLevelValue(33.2);
final Snow snow = Snow.withOneHourLevelValue(33.1);
Assert.assertNotEquals("", weather.toString());
Assert.assertNotNull(weather.toString());
@@ -252,7 +252,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Temperature temperature = Temperature.forValue(33.2, "as");
final Temperature temperature = Temperature.withValue(33.2, "as");
one.setTemperature(temperature);
Assert.assertFalse(one.equals(two));
@@ -261,7 +261,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(33.33);
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.33);
one.setAtmosphericPressure(atmosphericPressure);
Assert.assertFalse(one.equals(two));
@@ -270,7 +270,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Humidity humidity = Humidity.forValue((byte) 33);
final Humidity humidity = Humidity.withValue((byte) 33);
one.setHumidity(humidity);
Assert.assertFalse(one.equals(two));
@@ -279,7 +279,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Wind wind = Wind.forValue(33.6, "asd");
final Wind wind = Wind.withValue(33.6, "asd");
one.setWind(wind);
Assert.assertFalse(one.equals(two));
@@ -288,7 +288,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Rain rain = new Rain();
final Rain rain = Rain.withValues(0, 0);
one.setRain(rain);
Assert.assertFalse(one.equals(two));
@@ -297,7 +297,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Snow snow = new Snow();
final Snow snow = Snow.withValues(0, 0);
one.setSnow(snow);
Assert.assertFalse(one.equals(two));
@@ -306,7 +306,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Clouds clouds = Clouds.forValue((byte) 33);
final Clouds clouds = Clouds.withValue((byte) 33);
one.setClouds(clouds);
Assert.assertFalse(one.equals(two));
@@ -315,7 +315,7 @@ public class WeatherUnitTest {
Assert.assertTrue(one.equals(two));
final Location location = Location.forValue(231, "asda");
final Location location = Location.withValues(231, "asda");
one.setLocation(location);
Assert.assertFalse(one.equals(two));
@@ -28,22 +28,22 @@ import org.junit.Test;
public class WindUnitTest {
@Test
public void whenCreateWindWithValidArgs_thenValueIsSet() {
Assert.assertEquals(44.0, Wind.forValue(44, "ms").getSpeed(), 0.00001);
Assert.assertEquals(44.0, Wind.withValue(44, "ms").getSpeed(), 0.00001);
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateWindWithInvalidSpeedArg_thenThrowAnException() {
Wind.forValue(-21, "a");
Wind.withValue(-21, "a");
}
@Test(expected = IllegalArgumentException.class)
public void whenCreateWindWithInvalidUnitArg_thenThrowAnException() {
Wind.forValue(342, null);
Wind.withValue(342, null);
}
@Test
public void whenSetValidSpeed_thenValueIsSet() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
@@ -58,7 +58,7 @@ public class WindUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidSpeedBelow0_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
@@ -67,7 +67,7 @@ public class WindUnitTest {
@Test
public void whenSetValidDegrees_thenValueIsSet() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertNull(wind.getDegrees());
@@ -86,19 +86,19 @@ public class WindUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidDegreesBelow0_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setDegrees(-32);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidDegreesAbove360_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setDegrees(378);
}
@Test
public void whenSetNonNullUnit_thenValueIsSet() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
Assert.assertEquals(wind.getUnit(), "as");
@@ -109,21 +109,21 @@ public class WindUnitTest {
@Test(expected = IllegalArgumentException.class)
public void whenSetNullUnit_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setUnit(null);
}
@Test(expected = IllegalArgumentException.class)
public void whenSetInvalidGustValue_thenThrowAnException() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setGust(-50);
}
@Test
public void whenSetValidGustValue_thenAllIsFine() {
final Wind wind = Wind.forValue(33, "as");
final Wind wind = Wind.withValue(33, "as");
wind.setGust(30);
@@ -132,7 +132,7 @@ public class WindUnitTest {
@Test
public void whenCallToString_thenAllIsFine() {
final Wind wind = Wind.forValue(302, "a");
final Wind wind = Wind.withValue(302, "a");
Assert.assertNotNull(wind.toString());
@@ -148,8 +148,8 @@ public class WindUnitTest {
@Test
public void whenCallHashCode_thenAllIsFine() {
final Wind first = Wind.forValue(22, "a");
final Wind second = Wind.forValue(22, "b");
final Wind first = Wind.withValue(22, "a");
final Wind second = Wind.withValue(22, "b");
Assert.assertNotEquals(first.hashCode(), second.hashCode());
@@ -172,8 +172,8 @@ public class WindUnitTest {
@Test
public void whenCheckEquality_thenAllIsFine() {
final Wind first = Wind.forValue(11, "a");
final Wind second = Wind.forValue(11, "a");
final Wind first = Wind.withValue(11, "a");
final Wind second = Wind.withValue(11, "a");
Assert.assertTrue(first.equals(second));
Assert.assertTrue(first.equals(first));
@@ -252,7 +252,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
public void whenGetForecastByCoordinatesRequestAsJava_thenReturnNotNull() {
final Forecast forecast = getClient()
.forecast5Day3HourStep()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.count(15)
@@ -277,7 +277,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
public void whenGetForecastByCoordinatesRequestAsJSON_thenReturnNotNull() {
final String forecastJson = getClient()
.forecast5Day3HourStep()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.language(Language.SPANISH)
.unitSystem(UnitSystem.IMPERIAL)
.count(15)
@@ -291,7 +291,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
public void whenGetForecastByCoordinatesRequestAsXML_thenReturnNotNull() {
final String forecastXml = getClient()
.forecast5Day3HourStep()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@@ -44,7 +44,15 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byRectangle(CoordinateRectangle.forValues(12, 32, 15, 37), 10)
.byRectangle(
new CoordinateRectangle.Builder()
.setLongitudeLeft(12)
.setLatitudeBottom(32)
.setLongitudeRight(15)
.setLatitudeTop(37)
.build(),
10
)
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@@ -69,7 +77,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherJson = getClient()
.currentWeather()
.multiple()
.byRectangle(CoordinateRectangle.forValues(12, 32, 15, 37), 10)
.byRectangle(CoordinateRectangle.withValues(12, 32, 15, 37), 10)
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@@ -83,7 +91,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5))
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
@@ -109,7 +117,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherJson = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5))
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
@@ -123,7 +131,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherXml = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5))
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
@@ -138,7 +146,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
@@ -164,7 +172,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherJson = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
@@ -178,7 +186,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherXml = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
@@ -192,7 +200,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final CompletableFuture<List<Weather>> weatherListFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
@@ -209,7 +217,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10)
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
@@ -298,7 +298,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
final Weather weather = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
@@ -320,7 +320,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherJson = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJSON();
@@ -333,7 +333,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherXml = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asXML();
@@ -346,7 +346,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
final String weatherHtml = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.forValues(5, 5))
.byCoordinate(Coordinate.withValues(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asHTML();
@@ -550,7 +550,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
client
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(34.53, 66.74), 10)
.byCitiesInCycle(Coordinate.withValues(34.53, 66.74), 10)
.retrieve()
.asJSON();
}
@@ -560,7 +560,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.forValues(90.00, 66.74), 10)
.byCitiesInCycle(Coordinate.withValues(90.00, 66.74), 10)
.retrieve()
.asJava();
}
@@ -1,3 +1,25 @@
/*
* Copyright (c) 2021 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.utils;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;