BATCH-1316: adjust default values for long and double
This commit is contained in:
@@ -55,6 +55,9 @@ public class JobParameters implements Serializable {
|
||||
* @return The <code>Long</code> value
|
||||
*/
|
||||
public long getLong(String key){
|
||||
if (!parameters.containsKey(key)) {
|
||||
return 0L;
|
||||
}
|
||||
Object value = parameters.get(key).getValue();
|
||||
return value==null ? 0L : ((Long)value).longValue();
|
||||
}
|
||||
@@ -113,7 +116,11 @@ public class JobParameters implements Serializable {
|
||||
* @return The <code>Double</code> value
|
||||
*/
|
||||
public double getDouble(String key){
|
||||
return ((Double)parameters.get(key).getValue()).doubleValue();
|
||||
if (!parameters.containsKey(key)) {
|
||||
return 0L;
|
||||
}
|
||||
Double value = (Double)parameters.get(key).getValue();
|
||||
return value==null ? 0.0 : value.doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -85,6 +85,22 @@ public class JobParametersTests {
|
||||
assertEquals(null, parameters.getDate("date.key1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEmptyLong() {
|
||||
parameters = new JobParameters(Collections.singletonMap("long1", new JobParameter((Long)null)));
|
||||
assertEquals(0L, parameters.getLong("long1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMissingLong() {
|
||||
assertEquals(0L, parameters.getLong("missing.long1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMissingDouble() {
|
||||
assertEquals(0.0, parameters.getDouble("missing.double1"), 0.0001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsEmptyWhenEmpty() throws Exception {
|
||||
assertTrue(new JobParameters().isEmpty());
|
||||
|
||||
Reference in New Issue
Block a user