mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-03 03:06:45 +03:00
2.1.1 version implementation.
This commit is contained in:
+13
@@ -254,6 +254,19 @@ public class Daily {
|
||||
this.probabilityOfPrecipitation = probabilityOfPrecipitation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets probability of precipitation percentage.
|
||||
*
|
||||
* @return the probability of precipitation percentage
|
||||
*/
|
||||
public Byte getProbabilityOfPrecipitationPercentage() {
|
||||
if (probabilityOfPrecipitation != null) {
|
||||
return (byte)(probabilityOfPrecipitation * 100);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets rain.
|
||||
*
|
||||
|
||||
+16
@@ -225,9 +225,25 @@ public class Hourly {
|
||||
* @param probabilityOfPrecipitation the probability of precipitation
|
||||
*/
|
||||
public void setProbabilityOfPrecipitation(Double probabilityOfPrecipitation) {
|
||||
if (probabilityOfPrecipitation != null && (probabilityOfPrecipitation < 0 || probabilityOfPrecipitation > 100)) {
|
||||
throw new IllegalArgumentException("Probability of precipitation value must be in [0, 100] range.");
|
||||
}
|
||||
this.probabilityOfPrecipitation = probabilityOfPrecipitation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets probability of precipitation percentage.
|
||||
*
|
||||
* @return the probability of precipitation percentage
|
||||
*/
|
||||
public Byte getProbabilityOfPrecipitationPercentage() {
|
||||
if (probabilityOfPrecipitation != null) {
|
||||
return (byte)(probabilityOfPrecipitation * 100);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets rain.
|
||||
*
|
||||
|
||||
+3
-1
@@ -141,14 +141,16 @@ public class DailyUnitTest {
|
||||
@Test
|
||||
public void getProbabilityOfPrecipitation() {
|
||||
final Daily daily = new Daily();
|
||||
final double pop = 70.5;
|
||||
final double pop = 0.84;
|
||||
daily.setProbabilityOfPrecipitation(pop);
|
||||
|
||||
assertEquals(pop, daily.getProbabilityOfPrecipitation(), 0.00001);
|
||||
assertEquals((byte) 84, daily.getProbabilityOfPrecipitationPercentage());
|
||||
|
||||
daily.setProbabilityOfPrecipitation(null);
|
||||
|
||||
assertNull(daily.getProbabilityOfPrecipitation());
|
||||
assertNull(daily.getProbabilityOfPrecipitationPercentage());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+21
-1
@@ -117,10 +117,30 @@ public class HourlyUnitTest {
|
||||
@Test
|
||||
public void getProbabilityOfPrecipitation() {
|
||||
final Hourly hourly = new Hourly();
|
||||
final double pop = 42.0;
|
||||
final double pop = 0.84;
|
||||
hourly.setProbabilityOfPrecipitation(pop);
|
||||
|
||||
assertEquals(pop, hourly.getProbabilityOfPrecipitation(), 0.00001);
|
||||
assertEquals((byte) 84, hourly.getProbabilityOfPrecipitationPercentage());
|
||||
|
||||
hourly.setProbabilityOfPrecipitation(null);
|
||||
|
||||
assertNull(hourly.getProbabilityOfPrecipitation());
|
||||
assertNull(hourly.getProbabilityOfPrecipitationPercentage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIllegalProbabilityOfPrecipitationValue_negative() {
|
||||
final Hourly daily = new Hourly();
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> daily.setProbabilityOfPrecipitation(-20.0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIllegalProbabilityOfPrecipitationValue_tooBig() {
|
||||
final Hourly daily = new Hourly();
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> daily.setProbabilityOfPrecipitation(120.0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user