mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-04 03:36:44 +03:00
Added draft unit tests for model to cover all lines.
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.test;
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.github.prominence.openweathermap.api.impl.OpenWeatherMapClient;
|
||||
import org.junit.BeforeClass;
|
||||
+48
-26
@@ -20,11 +20,14 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.test;
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.github.prominence.openweathermap.api.enums.Accuracy;
|
||||
import com.github.prominence.openweathermap.api.enums.Language;
|
||||
import com.github.prominence.openweathermap.api.enums.Unit;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||
import com.github.prominence.openweathermap.api.impl.OpenWeatherMapClient;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
@@ -43,8 +46,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byCoordinate(new Coordinate(5, 5))
|
||||
.accuracy(Accuracy.ACCURATE)
|
||||
.language(Language.ROMANIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@@ -59,7 +61,6 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byCityId(350001514)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@@ -74,7 +75,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byCityName("Minsk")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@@ -89,7 +90,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byCityName("Moscow", "ru")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@@ -104,7 +105,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@@ -119,7 +120,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
@@ -134,7 +135,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
@@ -149,7 +150,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asHTML();
|
||||
|
||||
@@ -164,7 +165,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
|
||||
@@ -179,7 +180,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
@@ -194,7 +195,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
@@ -209,7 +210,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asHTML();
|
||||
|
||||
@@ -225,7 +226,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.byRectangle(new CoordinateRectangle(12, 32, 15, 37), 10)
|
||||
.accuracy(Accuracy.ACCURATE)
|
||||
.language(Language.ROMANIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@@ -242,7 +243,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.byRectangle(new CoordinateRectangle(12, 32, 15, 37), 10, true)
|
||||
.accuracy(Accuracy.ACCURATE)
|
||||
.language(Language.ROMANIAN)
|
||||
.unit(Unit.METRIC_SYSTEM)
|
||||
.unitSystem(UnitSystem.METRIC_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@@ -258,7 +259,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@@ -274,7 +275,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
@@ -290,7 +291,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
@@ -305,7 +306,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
@@ -320,7 +321,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieve()
|
||||
.asHTML();
|
||||
|
||||
@@ -335,7 +336,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
@@ -352,7 +353,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
|
||||
@@ -367,7 +368,7 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
@@ -382,11 +383,32 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
|
||||
.multiple()
|
||||
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
|
||||
.language(Language.GERMAN)
|
||||
.unit(Unit.IMPERIAL_SYSTEM)
|
||||
.unitSystem(UnitSystem.IMPERIAL_SYSTEM)
|
||||
.retrieveAsync()
|
||||
.asHTML();
|
||||
|
||||
assert weatherFuture != null;
|
||||
System.out.println(weatherFuture.get());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidAuthTokenException.class)
|
||||
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
|
||||
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
|
||||
client
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCityName("London")
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
|
||||
getClient()
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCityName("InvalidCity")
|
||||
.retrieve()
|
||||
.asJava();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CloudsUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateCloudsWithValidArgs_thenValueIsSet() {
|
||||
Clouds clouds = new Clouds((byte) 100);
|
||||
assert clouds.getValue() == 100;
|
||||
|
||||
assert new Clouds((byte) 0).getValue() == 0;
|
||||
assert new Clouds((byte) 100).getValue() == 100;
|
||||
assert new Clouds((byte) 55).getValue() == 55;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCloudsByConstructorWithInvalidDataAboveHundred_thenThrowAnException() {
|
||||
new Clouds((byte) 110);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCloudsByConstructorWithInvalidDataNegative_thenThrowAnException() {
|
||||
new Clouds((byte) -33);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValidValues_thenAllIsFine() {
|
||||
Clouds clouds = new Clouds((byte) 14);
|
||||
clouds.setValue((byte) 0);
|
||||
clouds.setValue((byte) 15);
|
||||
clouds.setValue((byte) 100);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCloudsAndSetInvalidDataAboveHundred_thenThrowAnException() {
|
||||
Clouds clouds = new Clouds((byte) 12);
|
||||
clouds.setValue((byte) 112);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCloudsAndSetInvalidDataNegative_thenThrowAnException() {
|
||||
Clouds clouds = new Clouds((byte) 88);
|
||||
clouds.setValue((byte) -89);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
|
||||
Clouds one = new Clouds((byte) 22);
|
||||
Clouds two = new Clouds((byte) 22);
|
||||
|
||||
assert one.equals(two);
|
||||
assert one.equals(one);
|
||||
assert one.hashCode() == two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
|
||||
Clouds one = new Clouds((byte) 5);
|
||||
Clouds two = new Clouds((byte) 88);
|
||||
|
||||
assert !one.equals(two);
|
||||
assert !two.equals(one);
|
||||
assert !one.equals(new Object());
|
||||
assert one.hashCode() != two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final String cloudsString = new Clouds((byte) 44).toString();
|
||||
assert cloudsString != null;
|
||||
assert !"".equals(cloudsString);
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CoordinateRectangleUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||
new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLatitudeBottomBelowMinus90_thenThrowAnException() {
|
||||
new CoordinateRectangle(44.5, -91.2, 54.4, 22.2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLatitudeBottomAbove90_thenThrowAnException() {
|
||||
new CoordinateRectangle(44.5, 91.2, 54.4, 22.2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLatitudeTopBelowMinus90_thenThrowAnException() {
|
||||
new CoordinateRectangle(44.5, 22.4, 54.4, -92.3);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLatitudeTopAbove90_thenThrowAnException() {
|
||||
new CoordinateRectangle(44.5, 22.5, 54.4, 94.887);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLongitudeLeftBelowMinus180_thenThrowAnException() {
|
||||
new CoordinateRectangle(-944.5, 22.4, 54.4, 22.2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLongitudeLeftAbove180_thenThrowAnException() {
|
||||
new CoordinateRectangle(544.5, 22.4, 54.4, 22.2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLongitudeRightBelowMinus180_thenThrowAnException() {
|
||||
new CoordinateRectangle(44.5, 22.4, -254.4, 22.2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithLongitudeRightAbove180_thenThrowAnException() {
|
||||
new CoordinateRectangle(44.5, 22.4, 354.4, 22.2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetAllParameters_thenAllIsFine() {
|
||||
final CoordinateRectangle rectangle = new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
assert rectangle.getLongitudeLeft() == 44.5;
|
||||
assert rectangle.getLatitudeBottom() == 22.4;
|
||||
assert rectangle.getLongitudeRight() == 54.4;
|
||||
assert rectangle.getLatitudeTop() == 22.2;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final CoordinateRectangle rectangle = new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
|
||||
assert rectangle.toString() != null;
|
||||
assert !"".equals(rectangle.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallHashCode_thenAllIsFine() {
|
||||
final CoordinateRectangle first = new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
final CoordinateRectangle second = new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
final CoordinateRectangle third = new CoordinateRectangle(44.5, 22.4, 54.4, 23.566);
|
||||
|
||||
assert first.hashCode() != third.hashCode();
|
||||
assert second.hashCode() != third.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
CoordinateRectangle first = new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
CoordinateRectangle second = new CoordinateRectangle(44.5, 22.4, 54.4, 22.2);
|
||||
|
||||
assert first.equals(second);
|
||||
assert first.equals(first);
|
||||
assert !first.equals(new Object());
|
||||
|
||||
first = new CoordinateRectangle(49.5, 22.4, 54.4, 22.2);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first = new CoordinateRectangle(44.5, 29.4, 54.4, 22.2);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first = new CoordinateRectangle(44.5, 22.4, 24.4, 22.2);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first = new CoordinateRectangle(44.5, 22.4, 54.4, -2.2);
|
||||
|
||||
assert !first.equals(second);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CoordinateUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateCoordinateWithValidValues_thenObjectCreated() {
|
||||
new Coordinate(44, 53);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCoordinateWithInvalidLatitudeBelowMinus90_thenThrowAnException() {
|
||||
new Coordinate(-333, 44);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCoordinateWithInvalidLatitudeAbove90_thenThrowAnException() {
|
||||
new Coordinate(223, 44);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCoordinateWithInvalidLongitudeBelowMinus180_thenThrowAnException() {
|
||||
new Coordinate(33, -999);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateCoordinateWithInvalidLongitudeAbove180_thenThrowAnException() {
|
||||
new Coordinate(33, 999);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValidCoordinates_thenAllIsFine() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
|
||||
coordinate.setLatitude(-90);
|
||||
coordinate.setLatitude(90);
|
||||
coordinate.setLatitude(44);
|
||||
|
||||
coordinate.setLongitude(-180);
|
||||
coordinate.setLongitude(180);
|
||||
coordinate.setLongitude(130);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidLatitudeBelowMinus90_thenThrowAnException() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
coordinate.setLatitude(-91);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidLatitudeAbove90_thenThrowAnException() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
coordinate.setLatitude(92);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidLongitudeBelowMinus180_thenThrowAnException() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
coordinate.setLongitude(-194);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidLongitudeAbove180_thenThrowAnException() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
coordinate.setLongitude(444);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetLatitude_thenAllIsFine() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
assert coordinate.getLatitude() == 0;
|
||||
|
||||
coordinate.setLatitude(45);
|
||||
|
||||
assert coordinate.getLatitude() == 45;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetLongitude_thenAllIsFine() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
assert coordinate.getLongitude() == 0;
|
||||
|
||||
coordinate.setLongitude(33);
|
||||
|
||||
assert coordinate.getLongitude() == 33;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Coordinate coordinate = new Coordinate(0, 0);
|
||||
assert coordinate.toString() != null;
|
||||
assert !"".equals(coordinate.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void RainwhenCallHashCode_thenAllIsFine() {
|
||||
final Coordinate first = new Coordinate(22, 66);
|
||||
final Coordinate second = new Coordinate(22, 44);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
second.setLongitude(66);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
second.setLatitude(89);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
first.setLatitude(89);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Coordinate first = new Coordinate(11, 99);
|
||||
final Coordinate second = new Coordinate(11, 99);
|
||||
|
||||
assert first.equals(second);
|
||||
assert first.equals(first);
|
||||
assert !first.equals(new Object());
|
||||
|
||||
first.setLatitude(34);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
second.setLatitude(34);
|
||||
|
||||
assert first.equals(second);
|
||||
|
||||
second.setLongitude(74);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first.setLongitude(74);
|
||||
|
||||
assert first.equals(second);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class HumidityUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateHumidityWithArgs_thenValueIsSet() {
|
||||
Humidity humidity = new Humidity((byte) 100);
|
||||
assert humidity.getValue() == 100;
|
||||
|
||||
assert new Humidity((byte) 0).getValue() == 0;
|
||||
assert new Humidity((byte) 100).getValue() == 100;
|
||||
assert new Humidity((byte) 55).getValue() == 55;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateHumidityByConstructorWithInvalidDataAboveHundred_thenThrowAnException() {
|
||||
new Humidity((byte) 112);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateHumidityByConstructorWithInvalidDataNegative_thenThrowAnException() {
|
||||
new Humidity((byte) -33);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValidValues_thenAllIsFine() {
|
||||
Humidity humidity = new Humidity((byte) 14);
|
||||
humidity.setValue((byte) 0);
|
||||
humidity.setValue((byte) 15);
|
||||
humidity.setValue((byte) 100);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateHumidityAndSetInvalidDataAboveHundred_thenThrowAnException() {
|
||||
Humidity humidity = new Humidity((byte) 12);
|
||||
humidity.setValue((byte) 112);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateHumidityAndSetInvalidDataNegative_thenThrowAnException() {
|
||||
Humidity humidity = new Humidity((byte) 88);
|
||||
humidity.setValue((byte) -89);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
|
||||
Humidity one = new Humidity((byte) 22);
|
||||
Humidity two = new Humidity((byte) 22);
|
||||
|
||||
assert one.equals(two);
|
||||
assert one.equals(one);
|
||||
assert one.hashCode() == two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
|
||||
Humidity one = new Humidity((byte) 5);
|
||||
Humidity two = new Humidity((byte) 88);
|
||||
|
||||
assert !one.equals(two);
|
||||
assert !two.equals(one);
|
||||
assert !one.equals(new Object());
|
||||
assert one.hashCode() != two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final String humidityString = new Humidity((byte) 44).toString();
|
||||
assert humidityString != null;
|
||||
assert !"".equals(humidityString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
public class LocationUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||
new Location(33, "test");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithoutName_thenThrowAnException() {
|
||||
new Location(33, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetId_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
location.setId(55);
|
||||
|
||||
assert location.getId() == 55;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetName_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
location.setName("city");
|
||||
|
||||
assert "city".equals(location.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetCountryCode_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
location.setCountryCode("by");
|
||||
|
||||
assert "by".equals(location.getCountryCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetSunrise_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
location.setSunrise(now);
|
||||
|
||||
assert now.equals(location.getSunrise());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetSunset_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
location.setSunset(now);
|
||||
|
||||
assert now.equals(location.getSunset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetZoneOffset_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
final ZoneOffset offset = ZoneOffset.UTC;
|
||||
location.setZoneOffset(offset);
|
||||
|
||||
assert offset.equals(location.getZoneOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetCoordinate_thenValueIsSet() {
|
||||
final Location location = new Location(33, "test");
|
||||
final Coordinate coordinate = new Coordinate(33.2, 64.2);
|
||||
location.setCoordinate(coordinate);
|
||||
|
||||
assert coordinate.equals(location.getCoordinate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Location location = new Location(44, "test");
|
||||
|
||||
assert !"".equals(location.toString());
|
||||
|
||||
location.setCoordinate(new Coordinate(33.2, 56.3));
|
||||
|
||||
assert !"".equals(location.toString());
|
||||
|
||||
location.setCountryCode("TN");
|
||||
|
||||
assert !"".equals(location.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallHashCode_thenAllIsFine() {
|
||||
final Location one = new Location(44, "test");
|
||||
final Location two = new Location(44, "test");
|
||||
|
||||
assert one.hashCode() == two.hashCode();
|
||||
|
||||
two.setName("112");
|
||||
|
||||
assert one.hashCode() != two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Location one = new Location(44, "test");
|
||||
final Location two = new Location(44, "test");
|
||||
|
||||
assert one.equals(one);
|
||||
assert !one.equals(new Object());
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
two.setId(23);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
one.setId(23);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setName("23");
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setName("23");
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setCountryCode("11");
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setCountryCode("11");
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
one.setSunrise(now);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setSunrise(now);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setSunset(now);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setSunset(now);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setZoneOffset(ZoneOffset.UTC);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setZoneOffset(ZoneOffset.UTC);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Coordinate coordinate = new Coordinate(33.5, -22.4);
|
||||
|
||||
one.setCoordinate(coordinate);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setCoordinate(coordinate);
|
||||
|
||||
assert one.equals(two);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class PressureUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreatePressureWithArgs_thenValueIsSet() {
|
||||
Pressure pressure = new Pressure(100);
|
||||
assert pressure.getValue() == 100;
|
||||
|
||||
assert new Pressure(0).getValue() == 0;
|
||||
assert new Pressure(100).getValue() == 100;
|
||||
assert new Pressure(55).getValue() == 55;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
|
||||
Pressure one = new Pressure(22);
|
||||
Pressure two = new Pressure(22);
|
||||
|
||||
assert one.equals(two);
|
||||
assert one.equals(one);
|
||||
assert one.hashCode() == two.hashCode();
|
||||
|
||||
one.setSeaLevelValue(333);
|
||||
one.setGroundLevelValue(555);
|
||||
|
||||
two.setSeaLevelValue(333);
|
||||
two.setGroundLevelValue(555);
|
||||
|
||||
assert one.equals(two);
|
||||
assert two.equals(one);
|
||||
assert one.hashCode() == two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
|
||||
Pressure one = new Pressure(5);
|
||||
Pressure two = new Pressure(88);
|
||||
|
||||
assert !one.equals(two);
|
||||
assert !two.equals(one);
|
||||
assert !one.equals(new Object());
|
||||
assert one.hashCode() != two.hashCode();
|
||||
|
||||
one = new Pressure(44);
|
||||
one.setSeaLevelValue(44);
|
||||
two = new Pressure(44);
|
||||
two.setGroundLevelValue(22);
|
||||
|
||||
assert !one.equals(two);
|
||||
assert !two.equals(one);
|
||||
|
||||
two.setSeaLevelValue(44);
|
||||
|
||||
assert !one.equals(two);
|
||||
assert !two.equals(one);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValidValues_thenAllIsFine() {
|
||||
Pressure pressure = new Pressure(14);
|
||||
pressure.setValue(0);
|
||||
pressure.setValue(15);
|
||||
pressure.setValue(100);
|
||||
|
||||
pressure.setGroundLevelValue(222);
|
||||
assert pressure.getGroundLevelValue() == 222;
|
||||
|
||||
pressure.setSeaLevelValue(4232);
|
||||
assert pressure.getSeaLevelValue() == 4232;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final String pressureString = new Pressure(44).toString();
|
||||
assert pressureString != null;
|
||||
assert !"".equals(pressureString);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreatePressureByConstructorWithInvalidDataNegative_thenThrowAnException() {
|
||||
new Pressure(-33);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreatePressureAndSetInvalidDataNegative_thenThrowAnException() {
|
||||
Pressure pressure = new Pressure(88);
|
||||
pressure.setValue(-89);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidSeaLevelPressure_thenThrowAnException() {
|
||||
Pressure pressure = new Pressure(88);
|
||||
pressure.setSeaLevelValue(-89);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidGroundLevelPressure_thenThrowAnException() {
|
||||
Pressure pressure = new Pressure(88);
|
||||
pressure.setGroundLevelValue(-223);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class RainUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateRainWithValidArgs_thenObjectIsCreated() {
|
||||
new Rain(2222.3, 324234.3);
|
||||
new Rain(null, -213123.4);
|
||||
new Rain(-123123.123, null);
|
||||
new Rain(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValues_thenTheyAreSet() {
|
||||
final Rain snow = new Rain(null, null);
|
||||
|
||||
assert snow.getOneHourRainLevel() == null;
|
||||
assert snow.getThreeHourRainLevel() == null;
|
||||
|
||||
snow.setOneHourRainLevel(33.3);
|
||||
assert snow.getOneHourRainLevel() == 33.3;
|
||||
|
||||
snow.setThreeHourRainLevel(55.5);
|
||||
assert snow.getThreeHourRainLevel() == 55.5;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Rain snow = new Rain();
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert "unknown".equals(snow.toString());
|
||||
|
||||
snow.setThreeHourRainLevel(33.5);
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert !"unknown".equals(snow.toString());
|
||||
|
||||
snow.setOneHourRainLevel(22.2);
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert !"unknown".equals(snow.toString());
|
||||
|
||||
snow.setThreeHourRainLevel(null);
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert !"unknown".equals(snow.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallHashCode_thenAllIsFine() {
|
||||
final Rain first = new Rain();
|
||||
final Rain second = new Rain();
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
second.setThreeHourRainLevel(11.0);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
first.setThreeHourRainLevel(11.0);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
first.setOneHourRainLevel(333.2);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
second.setOneHourRainLevel(333.2);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Rain first = new Rain();
|
||||
final Rain second = new Rain();
|
||||
|
||||
assert first.equals(second);
|
||||
assert first.equals(first);
|
||||
assert !first.equals(new Object());
|
||||
|
||||
first.setOneHourRainLevel(0.34);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
second.setOneHourRainLevel(0.34);
|
||||
|
||||
assert first.equals(second);
|
||||
|
||||
second.setThreeHourRainLevel(66.7);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first.setThreeHourRainLevel(66.7);
|
||||
|
||||
assert first.equals(second);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SnowUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateSnowWithValidArgs_ObjectIsCreated() {
|
||||
new Snow(2222.3, 324234.3);
|
||||
new Snow(null, -213123.4);
|
||||
new Snow(-123123.123, null);
|
||||
new Snow(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValues_thenTheyAreSet() {
|
||||
final Snow snow = new Snow(null, null);
|
||||
|
||||
assert snow.getOneHourSnowLevel() == null;
|
||||
assert snow.getThreeHourSnowLevel() == null;
|
||||
|
||||
snow.setOneHourSnowLevel(33.3);
|
||||
assert snow.getOneHourSnowLevel() == 33.3;
|
||||
|
||||
snow.setThreeHourSnowLevel(55.5);
|
||||
assert snow.getThreeHourSnowLevel() == 55.5;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Snow snow = new Snow();
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert "unknown".equals(snow.toString());
|
||||
|
||||
snow.setThreeHourSnowLevel(33.5);
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert !"unknown".equals(snow.toString());
|
||||
|
||||
snow.setOneHourSnowLevel(22.2);
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert !"unknown".equals(snow.toString());
|
||||
|
||||
snow.setThreeHourSnowLevel(null);
|
||||
|
||||
assert snow.toString() != null;
|
||||
assert !"unknown".equals(snow.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void RainwhenCallHashCode_thenAllIsFine() {
|
||||
final Snow first = new Snow();
|
||||
final Snow second = new Snow();
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
second.setThreeHourSnowLevel(11.0);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
first.setThreeHourSnowLevel(11.0);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
first.setOneHourSnowLevel(333.2);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
second.setOneHourSnowLevel(333.2);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Snow first = new Snow();
|
||||
final Snow second = new Snow();
|
||||
|
||||
assert first.equals(second);
|
||||
assert first.equals(first);
|
||||
assert !first.equals(new Object());
|
||||
|
||||
first.setOneHourSnowLevel(0.34);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
second.setOneHourSnowLevel(0.34);
|
||||
|
||||
assert first.equals(second);
|
||||
|
||||
second.setThreeHourSnowLevel(66.7);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first.setThreeHourSnowLevel(66.7);
|
||||
|
||||
assert first.equals(second);
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TemperatureUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||
new Temperature(22.2, "K");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithEmptyUnit_thenThrowAnException() {
|
||||
new Temperature(22.2, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValue_thenAllIsFine() {
|
||||
final Temperature temperature = new Temperature(22.2, "K");
|
||||
temperature.setValue(55.44);
|
||||
|
||||
assert temperature.getValue() == 55.44;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetMaximumTemperature_thenAllIsOk() {
|
||||
final Temperature temperature = new Temperature(22.2, "K");
|
||||
temperature.setMaxTemperature(44.4);
|
||||
|
||||
assert temperature.getMaxTemperature() == 44.4;
|
||||
|
||||
temperature.setMaxTemperature(null);
|
||||
|
||||
assert temperature.getMaxTemperature() == null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetMinimumTemperature_thenAllIsOk() {
|
||||
final Temperature temperature = new Temperature(22.2, "K");
|
||||
temperature.setMinTemperature(33.2);
|
||||
|
||||
assert temperature.getMinTemperature() == 33.2;
|
||||
|
||||
temperature.setMinTemperature(null);
|
||||
|
||||
assert temperature.getMinTemperature() == null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetNonNullUnit_thenAllIsOk() {
|
||||
final Temperature temperature = new Temperature(22.2, "K");
|
||||
temperature.setUnit("test");
|
||||
|
||||
assert "test".equals(temperature.getUnit());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetNullUnit_thenThrowAnException() {
|
||||
final Temperature temperature = new Temperature(22.2, "K");
|
||||
|
||||
temperature.setUnit(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Temperature temperature = new Temperature(22.2, "K");
|
||||
|
||||
assert !"".equals(temperature.toString());
|
||||
|
||||
temperature.setMinTemperature(11.2);
|
||||
|
||||
assert !"".equals(temperature.toString());
|
||||
|
||||
temperature.setMaxTemperature(44.3);
|
||||
|
||||
assert !"".equals(temperature.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallHashCode_thenAllIsFine() {
|
||||
final Temperature one = new Temperature(22.2, "K");
|
||||
final Temperature two = new Temperature(22.2, "K");
|
||||
|
||||
assert one.hashCode() == two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Temperature one = new Temperature(22.2, "K");
|
||||
final Temperature two = new Temperature(21.2, "K");
|
||||
|
||||
assert one.equals(one);
|
||||
assert !one.equals(new Object());
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
one.setValue(21.2);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setMaxTemperature(33.56);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setMaxTemperature(33.56);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setMinTemperature(11.54);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setMinTemperature(11.54);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
two.setUnit("U");
|
||||
|
||||
assert !one.equals(two);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class WeatherUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||
new Weather("state", "desc");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithoutState_thenThrowAnException() {
|
||||
new Weather(null, "desc");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateObjectWithoutDescription_thenThrowAnException() {
|
||||
new Weather("state", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetState_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
weather.setState("test");
|
||||
|
||||
assert "test".equals(weather.getState());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetNullState_thenThrowAnException() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
weather.setState(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetDescription_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
weather.setDescription("test");
|
||||
|
||||
assert "test".equals(weather.getDescription());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetNullDescription_thenThrowAnException() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
weather.setDescription(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetIconUrl_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
weather.setWeatherIconUrl("test");
|
||||
|
||||
assert "test".equals(weather.getWeatherIconUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetRequestedOn_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
weather.setRequestedOn(now);
|
||||
|
||||
assert now.equals(weather.getRequestedOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetTemperature_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Temperature temperature = new Temperature(22.3, "a");
|
||||
weather.setTemperature(temperature);
|
||||
|
||||
assert temperature.equals(weather.getTemperature());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetPressure_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Pressure pressure = new Pressure(33.2);
|
||||
weather.setPressure(pressure);
|
||||
|
||||
assert pressure.equals(weather.getPressure());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetHumidity_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Humidity humidity = new Humidity((byte) 44);
|
||||
weather.setHumidity(humidity);
|
||||
|
||||
assert humidity.equals(weather.getHumidity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetWind_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Wind wind = new Wind(22.2, "a");
|
||||
weather.setWind(wind);
|
||||
|
||||
assert wind.equals(weather.getWind());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetRain_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Rain rain = new Rain();
|
||||
weather.setRain(rain);
|
||||
|
||||
assert rain.equals(weather.getRain());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetSnow_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Snow snow = new Snow();
|
||||
weather.setSnow(snow);
|
||||
|
||||
assert snow.equals(weather.getSnow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetClouds_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Clouds clouds = new Clouds((byte) 33);
|
||||
weather.setClouds(clouds);
|
||||
|
||||
assert clouds.equals(weather.getClouds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetLocation_thenValueIsSet() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Location location = new Location(22, "asd");
|
||||
weather.setLocation(location);
|
||||
|
||||
assert location.equals(weather.getLocation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Weather weather = new Weather("state", "desc");
|
||||
final Location location = new Location(12312, "asd");
|
||||
final Temperature temperature = new Temperature(33.2, "asd");
|
||||
final Pressure pressure = new Pressure(44.4);
|
||||
final Clouds clouds = new Clouds((byte) 55);
|
||||
final Rain rain = new Rain(33.2, null);
|
||||
final Snow snow = new Snow(33.1, null);
|
||||
|
||||
assert !"".equals(weather.toString());
|
||||
weather.setLocation(location);
|
||||
assert !"".equals(weather.toString());
|
||||
location.setCountryCode("3d");
|
||||
assert !"".equals(weather.toString());
|
||||
weather.setTemperature(temperature);
|
||||
assert !"".equals(weather.toString());
|
||||
weather.setPressure(pressure);
|
||||
assert !"".equals(weather.toString());
|
||||
weather.setClouds(clouds);
|
||||
assert !"".equals(weather.toString());
|
||||
weather.setRain(rain);
|
||||
assert !"".equals(weather.toString());
|
||||
weather.setSnow(snow);
|
||||
assert !"".equals(weather.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallHashCode_thenAllIsFine() {
|
||||
final Weather one = new Weather("state", "desc");
|
||||
final Weather two = new Weather("state", "desc");
|
||||
|
||||
assert one.hashCode() == two.hashCode();
|
||||
|
||||
two.setDescription("112");
|
||||
|
||||
assert one.hashCode() != two.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Weather one = new Weather("state", "desc");
|
||||
final Weather two = new Weather("state1", "desc1");
|
||||
|
||||
assert one.equals(one);
|
||||
assert !one.equals(new Object());
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setState("state");
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setDescription("desc");
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
one.setWeatherIconUrl("1");
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setWeatherIconUrl("1");
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
one.setRequestedOn(now);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setRequestedOn(now);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Temperature temperature = new Temperature(33.2, "as");
|
||||
one.setTemperature(temperature);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setTemperature(temperature);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Pressure pressure = new Pressure(33.33);
|
||||
one.setPressure(pressure);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setPressure(pressure);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Humidity humidity = new Humidity((byte) 33);
|
||||
one.setHumidity(humidity);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setHumidity(humidity);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Wind wind = new Wind(33.6, "asd");
|
||||
one.setWind(wind);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setWind(wind);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Rain rain = new Rain();
|
||||
one.setRain(rain);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setRain(rain);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Snow snow = new Snow();
|
||||
one.setSnow(snow);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setSnow(snow);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Clouds clouds = new Clouds((byte) 33);
|
||||
one.setClouds(clouds);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setClouds(clouds);
|
||||
|
||||
assert one.equals(two);
|
||||
|
||||
final Location location = new Location(231, "asda");
|
||||
one.setLocation(location);
|
||||
|
||||
assert !one.equals(two);
|
||||
|
||||
two.setLocation(location);
|
||||
|
||||
assert one.equals(two);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class WindUnitTest {
|
||||
@Test
|
||||
public void whenCreateWindWithValidArgs_thenValueIsSet() {
|
||||
assert new Wind(44, "ms").getSpeed() == 44.0;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateWindWithInvalidSpeedArg_thenThrowAnException() {
|
||||
new Wind(-21, "a");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateWindWithInvalidUnitArg_thenThrowAnException() {
|
||||
new Wind(342, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValidSpeed_thenValueIsSet() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
|
||||
assert wind.getSpeed() == 33;
|
||||
|
||||
wind.setSpeed(0);
|
||||
|
||||
assert wind.getSpeed() == 0;
|
||||
|
||||
wind.setSpeed(3656);
|
||||
|
||||
assert wind.getSpeed() == 3656;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidSpeedBelow0_thenThrowAnException() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
|
||||
assert wind.getSpeed() == 33;
|
||||
|
||||
wind.setSpeed(-22);
|
||||
|
||||
assert false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetValidDegrees_thenValueIsSet() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
|
||||
assert wind.getDegrees() == null;
|
||||
|
||||
wind.setDegrees(22);
|
||||
|
||||
assert wind.getDegrees() == 22;
|
||||
|
||||
wind.setDegrees(0);
|
||||
|
||||
assert wind.getDegrees() == 0;
|
||||
|
||||
wind.setDegrees(360);
|
||||
|
||||
assert wind.getDegrees() == 360;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidDegreesBelow0_thenThrowAnException() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
wind.setDegrees(-32);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetInvalidDegreesAbove360_thenThrowAnException() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
wind.setDegrees(378);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetNonNullUnit_thenValueIsSet() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
|
||||
assert "as".equals(wind.getUnit());
|
||||
|
||||
wind.setUnit("myUnit");
|
||||
|
||||
assert "myUnit".equals(wind.getUnit());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSetNullUnit_thenThrowAnException() {
|
||||
final Wind wind = new Wind(33, "as");
|
||||
|
||||
wind.setUnit(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallToString_thenAllIsFine() {
|
||||
final Wind wind = new Wind(302, "a");
|
||||
|
||||
assert wind.toString() != null;
|
||||
|
||||
wind.setDegrees(22);
|
||||
|
||||
assert wind.toString() != null && !"".equals(wind.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void RainwhenCallHashCode_thenAllIsFine() {
|
||||
final Wind first = new Wind(22, "a");
|
||||
final Wind second = new Wind(22, "b");
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
second.setUnit("a");
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
|
||||
second.setSpeed(33);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
first.setSpeed(333);
|
||||
|
||||
assert first.hashCode() != second.hashCode();
|
||||
|
||||
first.setSpeed(33);
|
||||
|
||||
assert first.hashCode() == second.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckEquality_thenAllIsFine() {
|
||||
final Wind first = new Wind(11, "a");
|
||||
final Wind second = new Wind(11, "a");
|
||||
|
||||
assert first.equals(second);
|
||||
assert first.equals(first);
|
||||
assert !first.equals(new Object());
|
||||
|
||||
first.setDegrees(34);
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
second.setDegrees(34);
|
||||
|
||||
assert first.equals(second);
|
||||
|
||||
second.setUnit("v");
|
||||
|
||||
assert !first.equals(second);
|
||||
|
||||
first.setUnit("v");
|
||||
first.setSpeed(second.getSpeed() + 4);
|
||||
|
||||
assert !first.equals(second);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.github.prominence.openweathermap.api.utils;
|
||||
|
||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RequestUtilsUnitTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenPassInvalidUrl_thenThrowAnException() {
|
||||
RequestUtils.getResponse("wrongUrl");
|
||||
}
|
||||
|
||||
@Test(expected = DataNotFoundException.class)
|
||||
public void whenPassUrlToNonExistingPage_thenThrowAnException() {
|
||||
RequestUtils.getResponse("https://openweathermap.org/somePage");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user