Fix getDouble to use Double.valueOf instead of Float.valueOf for
conversions.
This commit is contained in:
Timothy Bish 2015-03-03 16:28:28 -05:00
parent 6e038d5ffd
commit 4b346360be
2 changed files with 24 additions and 11 deletions

View File

@ -437,22 +437,19 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
public double getDouble(String name) throws JMSException {
initializeReading();
Object value = map.get(name);
if (value == null) {
return 0;
}
if (value instanceof Double) {
} else if (value instanceof Double) {
return ((Double)value).doubleValue();
}
if (value instanceof Float) {
} else if (value instanceof Float) {
return ((Float)value).floatValue();
}
if (value instanceof UTF8Buffer) {
return Float.valueOf(value.toString()).floatValue();
}
if (value instanceof String) {
return Float.valueOf(value.toString()).floatValue();
} else if (value instanceof UTF8Buffer) {
return Double.valueOf(value.toString()).doubleValue();
} else if (value instanceof String) {
return Double.valueOf(value.toString()).doubleValue();
} else {
throw new MessageFormatException(" cannot read a double from " + value.getClass().getName());
throw new MessageFormatException("Cannot read a double from " + value.getClass().getName());
}
}

View File

@ -156,6 +156,22 @@ public class ActiveMQMapMessageTest {
assertTrue(msg.getDouble(this.name) == 1.5);
}
@Test(timeout = 10000)
public void testGetDoubleWithMaxValue() throws JMSException {
ActiveMQMapMessage msg = new ActiveMQMapMessage();
msg.setDouble(this.name, Double.MAX_VALUE);
msg = (ActiveMQMapMessage) msg.copy();
assertEquals(Double.MAX_VALUE, msg.getDouble(this.name), 1.0);
}
@Test(timeout = 10000)
public void testGetDoubleWithMaxValueAsString() throws JMSException {
ActiveMQMapMessage msg = new ActiveMQMapMessage();
msg.setString(this.name, String.valueOf(Double.MAX_VALUE));
msg = (ActiveMQMapMessage) msg.copy();
assertEquals(Double.MAX_VALUE, msg.getDouble(this.name), 1.0);
}
@Test(timeout = 10000)
public void testGetString() throws JMSException {
ActiveMQMapMessage msg = new ActiveMQMapMessage();