mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-04 03:36:44 +03:00
Implemented Solar Radiation API functionality. Small refactoring.
This commit is contained in:
+1
-1
@@ -72,7 +72,7 @@ class ClimaticForecastResponseMapperTest {
|
||||
|
||||
final Location location = forecast.getLocation();
|
||||
assertNotNull(location);
|
||||
assertEquals(Coordinates.of(51.5073, -0.1277), location.getCoordinate());
|
||||
assertEquals(Coordinates.of(51.5073, -0.1277), location.getCoordinates());
|
||||
assertEquals(2643743, location.getId());
|
||||
assertEquals("London", location.getName());
|
||||
assertEquals("GB", location.getCountryCode());
|
||||
|
||||
+4
-4
@@ -1096,7 +1096,7 @@ public class CurrentWeatherResponseMapperTest {
|
||||
|
||||
Weather weather = mapper.mapToWeather(jsonString);
|
||||
|
||||
assertNotNull(weather.getLocation().getCoordinate());
|
||||
assertNotNull(weather.getLocation().getCoordinates());
|
||||
assertNotNull(weather.getLocation().getCountryCode());
|
||||
|
||||
// without coordinates and country code
|
||||
@@ -1144,7 +1144,7 @@ public class CurrentWeatherResponseMapperTest {
|
||||
}
|
||||
""";
|
||||
weather = mapper.mapToWeather(jsonString);
|
||||
assertNull(weather.getLocation().getCoordinate());
|
||||
assertNull(weather.getLocation().getCoordinates());
|
||||
assertNull(weather.getLocation().getCountryCode());
|
||||
|
||||
// coordinates without latitude
|
||||
@@ -1196,7 +1196,7 @@ public class CurrentWeatherResponseMapperTest {
|
||||
}
|
||||
""";
|
||||
weather = mapper.mapToWeather(jsonString);
|
||||
assertNull(weather.getLocation().getCoordinate());
|
||||
assertNull(weather.getLocation().getCoordinates());
|
||||
assertNotNull(weather.getLocation().getCountryCode());
|
||||
|
||||
// coordinates without longitude
|
||||
@@ -1248,7 +1248,7 @@ public class CurrentWeatherResponseMapperTest {
|
||||
}
|
||||
""";
|
||||
weather = mapper.mapToWeather(jsonString);
|
||||
assertNull(weather.getLocation().getCoordinate());
|
||||
assertNull(weather.getLocation().getCoordinates());
|
||||
assertNotNull(weather.getLocation().getCountryCode());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -79,7 +79,7 @@ class DailyForecastResponseMapperTest {
|
||||
|
||||
final Location location = forecast.getLocation();
|
||||
assertNotNull(location);
|
||||
assertEquals(Coordinates.of(51.5085, -0.1258), location.getCoordinate());
|
||||
assertEquals(Coordinates.of(51.5085, -0.1258), location.getCoordinates());
|
||||
assertEquals(2643743, location.getId());
|
||||
assertEquals("London", location.getName());
|
||||
assertEquals("GB", location.getCountryCode());
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ class HourlyForecastResponseMapperTest {
|
||||
final Location location = hourlyForecast.getLocation();
|
||||
assertEquals(2643743, location.getId());
|
||||
assertEquals("London", location.getName());
|
||||
assertEquals(Coordinates.of(51.5085, -0.1258), location.getCoordinate());
|
||||
assertEquals(Coordinates.of(51.5085, -0.1258), location.getCoordinates());
|
||||
assertEquals("GB", location.getCountryCode());
|
||||
assertEquals(ZoneOffset.ofTotalSeconds(0), location.getZoneOffset());
|
||||
assertEquals(LocalDateTime.ofInstant(Instant.ofEpochSecond(1568958164), TimeZone.getDefault().toZoneId()), location.getSunriseTime());
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.github.prominence.openweathermap.api.mapper;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
import com.github.prominence.openweathermap.api.model.radiation.SolarRadiation;
|
||||
import com.github.prominence.openweathermap.api.model.radiation.SolarRadiationRecord;
|
||||
import com.github.prominence.openweathermap.api.utils.TestMappingUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class SolarRadiationResponseMapperTest {
|
||||
|
||||
@Test
|
||||
void mapToObject() {
|
||||
final String jsonResponse = """
|
||||
{
|
||||
"coord": {
|
||||
"lon": -114.6244,
|
||||
"lat": 32.7243
|
||||
},
|
||||
"list": [
|
||||
{
|
||||
"radiation": {
|
||||
"ghi": 206.68,
|
||||
"dni": 2.27,
|
||||
"dhi": 204.83,
|
||||
"ghi_cs": 826.71,
|
||||
"dni_cs": 885.47,
|
||||
"dhi_cs": 114.93
|
||||
},
|
||||
"dt": 1618232400
|
||||
}
|
||||
]
|
||||
}
|
||||
""";
|
||||
|
||||
final SolarRadiation solarRadiation = new SolarRadiationResponseMapper().mapToObject(jsonResponse);
|
||||
assertNotNull(solarRadiation);
|
||||
|
||||
assertEquals(Coordinates.of(32.7243, -114.6244), solarRadiation.getCoordinates());
|
||||
|
||||
final List<SolarRadiationRecord> records = solarRadiation.getSolarRadiationRecords();
|
||||
assertEquals(1, records.size());
|
||||
|
||||
final SolarRadiationRecord record = records.get(0);
|
||||
assertEquals(TestMappingUtils.parseDateTime(1618232400), record.getMeasurementTime());
|
||||
assertEquals(206.68, record.getCloudSkyGlobalHorizontalIrradiance());
|
||||
assertEquals(2.27, record.getCloudSkyDirectNormalIrradiance());
|
||||
assertEquals(204.83, record.getCloudSkyDiffuseHorizontalIrradiance());
|
||||
assertEquals(826.71, record.getClearSkyGlobalHorizontalIrradiance());
|
||||
assertEquals(885.47, record.getClearSkyDirectNormalIrradiance());
|
||||
assertEquals(114.93, record.getClearSkyDiffuseHorizontalIrradiance());
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -35,12 +35,12 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
public class AirPollutionDetailsUnitTest {
|
||||
@Test
|
||||
public void getCoordinate() {
|
||||
public void getCoordinates() {
|
||||
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
||||
final Coordinates coordinates = Coordinates.of(22.3, 44.2);
|
||||
airPollutionDetails.setCoordinate(coordinates);
|
||||
airPollutionDetails.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(coordinates, airPollutionDetails.getCoordinate());
|
||||
assertEquals(coordinates, airPollutionDetails.getCoordinates());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,11 +66,11 @@ public class AirPollutionDetailsUnitTest {
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setCoordinate(coordinates);
|
||||
first.setCoordinates(coordinates);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setCoordinate(coordinates);
|
||||
second.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
@@ -91,7 +91,7 @@ public class AirPollutionDetailsUnitTest {
|
||||
|
||||
assertEquals(first.hashCode(), second.hashCode());
|
||||
|
||||
first.setCoordinate(coordinates);
|
||||
first.setCoordinates(coordinates);
|
||||
|
||||
assertNotEquals(first.hashCode(), second.hashCode());
|
||||
}
|
||||
|
||||
+5
-5
@@ -96,9 +96,9 @@ public class LocationUnitTest {
|
||||
public void whenSetCoordinate_thenValueIsSet() {
|
||||
final Location location = Location.withValues(33, "test");
|
||||
final Coordinates coordinates = Coordinates.of(33.2, 64.2);
|
||||
location.setCoordinate(coordinates);
|
||||
location.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(coordinates, location.getCoordinate());
|
||||
assertEquals(coordinates, location.getCoordinates());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,7 +115,7 @@ public class LocationUnitTest {
|
||||
|
||||
assertNotEquals("", location.toString());
|
||||
|
||||
location.setCoordinate(Coordinates.of(33.2, 56.3));
|
||||
location.setCoordinates(Coordinates.of(33.2, 56.3));
|
||||
|
||||
assertNotEquals("", location.toString());
|
||||
|
||||
@@ -203,11 +203,11 @@ public class LocationUnitTest {
|
||||
|
||||
final Coordinates coordinates = Coordinates.of(33.5, -22.4);
|
||||
|
||||
one.setCoordinate(coordinates);
|
||||
one.setCoordinates(coordinates);
|
||||
|
||||
assertNotEquals(one, two);
|
||||
|
||||
two.setCoordinate(coordinates);
|
||||
two.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(one, two);
|
||||
|
||||
|
||||
+7
-7
@@ -35,12 +35,12 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CurrentWeatherDataUnitTest {
|
||||
@Test
|
||||
public void getCoordinate() {
|
||||
public void getCoordinates() {
|
||||
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
|
||||
final Coordinates coordinates = Coordinates.of(11.2, 43.2);
|
||||
currentWeatherData.setCoordinate(coordinates);
|
||||
currentWeatherData.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(coordinates, currentWeatherData.getCoordinate());
|
||||
assertEquals(coordinates, currentWeatherData.getCoordinates());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,11 +126,11 @@ public class CurrentWeatherDataUnitTest {
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setCoordinate(coordinates);
|
||||
first.setCoordinates(coordinates);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setCoordinate(coordinates);
|
||||
second.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
@@ -198,7 +198,7 @@ public class CurrentWeatherDataUnitTest {
|
||||
|
||||
assertEquals(first.hashCode(), second.hashCode());
|
||||
|
||||
first.setCoordinate(Coordinates.of(11, 42));
|
||||
first.setCoordinates(Coordinates.of(11, 42));
|
||||
|
||||
assertNotEquals(first.hashCode(), second.hashCode());
|
||||
}
|
||||
@@ -206,7 +206,7 @@ public class CurrentWeatherDataUnitTest {
|
||||
@Test
|
||||
public void getToString() {
|
||||
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
|
||||
currentWeatherData.setCoordinate(Coordinates.of(32, 22));
|
||||
currentWeatherData.setCoordinates(Coordinates.of(32, 22));
|
||||
|
||||
assertNotNull(currentWeatherData.toString());
|
||||
assertNotEquals("", currentWeatherData.toString());
|
||||
|
||||
+7
-7
@@ -34,12 +34,12 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class HistoricalWeatherDataUnitTest {
|
||||
@Test
|
||||
public void getCoordinate() {
|
||||
public void getCoordinates() {
|
||||
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
|
||||
final Coordinates coordinates = Coordinates.of(11.2, 43.2);
|
||||
historicalWeatherData.setCoordinate(coordinates);
|
||||
historicalWeatherData.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(coordinates, historicalWeatherData.getCoordinate());
|
||||
assertEquals(coordinates, historicalWeatherData.getCoordinates());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,11 +95,11 @@ public class HistoricalWeatherDataUnitTest {
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setCoordinate(coordinates);
|
||||
first.setCoordinates(coordinates);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setCoordinate(coordinates);
|
||||
second.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
@@ -143,7 +143,7 @@ public class HistoricalWeatherDataUnitTest {
|
||||
|
||||
assertEquals(first.hashCode(), second.hashCode());
|
||||
|
||||
first.setCoordinate(Coordinates.of(11, 42));
|
||||
first.setCoordinates(Coordinates.of(11, 42));
|
||||
|
||||
assertNotEquals(first.hashCode(), second.hashCode());
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class HistoricalWeatherDataUnitTest {
|
||||
@Test
|
||||
public void getToString() {
|
||||
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
|
||||
historicalWeatherData.setCoordinate(Coordinates.of(32, 22));
|
||||
historicalWeatherData.setCoordinates(Coordinates.of(32, 22));
|
||||
|
||||
assertNotNull(historicalWeatherData.toString());
|
||||
assertNotEquals("", historicalWeatherData.toString());
|
||||
|
||||
+5
-5
@@ -96,9 +96,9 @@ public class LocationUnitTest {
|
||||
public void whenSetCoordinate_thenValueIsSet() {
|
||||
final Location location = Location.withValues(33, "test");
|
||||
final Coordinates coordinates = Coordinates.of(33.2, 64.2);
|
||||
location.setCoordinate(coordinates);
|
||||
location.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(coordinates, location.getCoordinate());
|
||||
assertEquals(coordinates, location.getCoordinates());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,7 +107,7 @@ public class LocationUnitTest {
|
||||
|
||||
assertNotEquals("", location.toString());
|
||||
|
||||
location.setCoordinate(Coordinates.of(33.2, 56.3));
|
||||
location.setCoordinates(Coordinates.of(33.2, 56.3));
|
||||
|
||||
assertNotEquals("", location.toString());
|
||||
|
||||
@@ -191,11 +191,11 @@ public class LocationUnitTest {
|
||||
|
||||
final Coordinates coordinates = Coordinates.of(33.5, -22.4);
|
||||
|
||||
one.setCoordinate(coordinates);
|
||||
one.setCoordinates(coordinates);
|
||||
|
||||
assertNotEquals(one, two);
|
||||
|
||||
two.setCoordinate(coordinates);
|
||||
two.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(one, two);
|
||||
}
|
||||
|
||||
+4
-4
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user