REOPENED - BATCH-618: DefaultJobParametersConverter does not parse parameters of type double
handle round doubles correctly
This commit is contained in:
@@ -106,13 +106,7 @@ public class DefaultJobParametersConverter implements JobParametersConverter {
|
||||
propertiesBuilder.addLong(StringUtils.replace(key, LONG_TYPE, ""), result);
|
||||
}
|
||||
else if (key.endsWith(DOUBLE_TYPE)) {
|
||||
Double result;
|
||||
try {
|
||||
result = (Double) parseNumber(value);
|
||||
}
|
||||
catch (ClassCastException ex) {
|
||||
throw new IllegalArgumentException("Number format is invalid for double value: [" + value + "]");
|
||||
}
|
||||
Double result = Double.valueOf(parseNumber(value).doubleValue());
|
||||
propertiesBuilder.addDouble(StringUtils.replace(key, DOUBLE_TYPE, ""), result);
|
||||
}
|
||||
else if (StringUtils.endsWithIgnoreCase(key, STRING_TYPE)) {
|
||||
|
||||
@@ -136,6 +136,16 @@ public class DefaultJobParametersConverterTests extends TestCase {
|
||||
assertNotNull(props);
|
||||
assertEquals(1.38, props.getDouble("value").doubleValue(), Double.MIN_VALUE);
|
||||
}
|
||||
|
||||
|
||||
public void testGetParametersWithRoundDouble() throws Exception {
|
||||
|
||||
String[] args = new String[] { "value(double)=1.0" };
|
||||
|
||||
JobParameters props = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
|
||||
assertNotNull(props);
|
||||
assertEquals((double) 1.0, props.getDouble("value").doubleValue(), Double.MIN_VALUE);
|
||||
}
|
||||
|
||||
public void testGetProperties() throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user