RESOLVED - BATCH-1853: If the JobParameters is asked for a Date value that doesn't exist, it will now return null rather than throwing NPE

This commit is contained in:
Lucas Ward
2012-05-04 10:17:16 -05:00
parent 60340e75b0
commit aa1c382c4c
2 changed files with 22 additions and 2 deletions

View File

@@ -148,7 +148,7 @@ public class JobParameters implements Serializable {
* @return The <code>java.util.Date</code> value
*/
public Date getDate(String key){
return (Date)parameters.get(key).getValue();
return this.getDate(key,null);
}
/**
@@ -162,7 +162,7 @@ public class JobParameters implements Serializable {
*/
public Date getDate(String key, Date defaultValue){
if(parameters.containsKey(key)){
return getDate(key);
return (Date)parameters.get(key).getValue();
}
else{
return defaultValue;

View File

@@ -191,4 +191,24 @@ public class JobParametersTests {
assertEquals(params, SerializationUtils.deserialize(serialized));
}
@Test
public void testLongReturns0WhenKeyDoesntExit(){
assertEquals(0L,new JobParameters().getLong("keythatdoesntexist"));
}
@Test
public void testStringReturnsNullWhenKeyDoesntExit(){
assertNull(new JobParameters().getString("keythatdoesntexist"));
}
@Test
public void testDoubleReturns0WhenKeyDoesntExit(){
assertEquals(0.0,new JobParameters().getLong("keythatdoesntexist"), 0.0001);
}
@Test
public void testDateReturnsNullWhenKeyDoesntExit(){
assertNull(new JobParameters().getDate("keythatdoesntexist"));
}
}