Return null instead of 0 when a Long/Double job parameter is absent

Resolves BATCH-2385
This commit is contained in:
Mahmoud Ben Hassine
2018-10-25 11:03:05 +02:00
parent 2d7caa3222
commit 9e02e935ce
3 changed files with 81 additions and 25 deletions

View File

@@ -33,6 +33,7 @@ import org.springframework.batch.core.launch.support.RunIdIncrementer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -131,10 +132,10 @@ public class JobParametersBuilderTests {
this.parametersBuilder.addDouble("DOUBLE", null);
JobParameters parameters = this.parametersBuilder.toJobParameters();
assertEquals(null, parameters.getDate("SCHEDULE_DATE"));
assertEquals(0L, parameters.getLong("LONG").longValue());
assertEquals(null, parameters.getString("STRING"));
assertEquals(0, parameters.getLong("DOUBLE").doubleValue(), 1e-15);
assertNull(parameters.getDate("SCHEDULE_DATE"));
assertNull(parameters.getLong("LONG"));
assertNull(parameters.getString("STRING"));
assertNull(parameters.getLong("DOUBLE"));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2014 the original author or authors.
* Copyright 2008-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@ import org.springframework.util.SerializationUtils;
* @author Lucas Ward
* @author Dave Syer
* @author Michael Minella
* @author Mahmoud Ben Hassine
*
*/
public class JobParametersTests {
@@ -74,7 +75,7 @@ public class JobParametersTests {
@Test
public void testGetNullString() {
parameters = new JobParameters(Collections.singletonMap("string.key1", new JobParameter((String) null, true)));
assertEquals(null, parameters.getDate("string.key1"));
assertNull(parameters.getDate("string.key1"));
}
@Test
@@ -98,23 +99,23 @@ public class JobParametersTests {
@Test
public void testGetNullDate() {
parameters = new JobParameters(Collections.singletonMap("date.key1", new JobParameter((Date)null, true)));
assertEquals(null, parameters.getDate("date.key1"));
assertNull(parameters.getDate("date.key1"));
}
@Test
public void testGetEmptyLong() {
parameters = new JobParameters(Collections.singletonMap("long1", new JobParameter((Long)null, true)));
assertEquals(0L, parameters.getLong("long1").longValue());
assertNull(parameters.getLong("long1"));
}
@Test
public void testGetMissingLong() {
assertEquals(0L, parameters.getLong("missing.long1").longValue());
assertNull(parameters.getLong("missing.long1"));
}
@Test
public void testGetMissingDouble() {
assertEquals(0.0, parameters.getDouble("missing.double1"), 0.0001);
assertNull(parameters.getDouble("missing.double1"));
}
@Test
@@ -209,8 +210,8 @@ public class JobParametersTests {
}
@Test
public void testLongReturns0WhenKeyDoesntExit(){
assertEquals(0L,new JobParameters().getLong("keythatdoesntexist").longValue());
public void testLongReturnsNullWhenKeyDoesntExit(){
assertNull(new JobParameters().getLong("keythatdoesntexist"));
}
@Test
@@ -219,8 +220,8 @@ public class JobParametersTests {
}
@Test
public void testDoubleReturns0WhenKeyDoesntExit(){
assertEquals(0.0,new JobParameters().getLong("keythatdoesntexist"), 0.0001);
public void testDoubleReturnsNullWhenKeyDoesntExit(){
assertNull(new JobParameters().getDouble("keythatdoesntexist"));
}
@Test