BATCH-1316: adjust default values for long and double

This commit is contained in:
Dave Syer
2011-04-05 08:59:28 +01:00
parent 70eb73f8c7
commit 9bbf1f5c72
2 changed files with 24 additions and 1 deletions

View File

@@ -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();
}
/**

View File

@@ -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());