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 { public double getDouble(String name) throws JMSException {
initializeReading(); initializeReading();
Object value = map.get(name); Object value = map.get(name);
if (value == null) { if (value == null) {
return 0; return 0;
} } else if (value instanceof Double) {
if (value instanceof Double) {
return ((Double)value).doubleValue(); return ((Double)value).doubleValue();
} } else if (value instanceof Float) {
if (value instanceof Float) {
return ((Float)value).floatValue(); return ((Float)value).floatValue();
} } else if (value instanceof UTF8Buffer) {
if (value instanceof UTF8Buffer) { return Double.valueOf(value.toString()).doubleValue();
return Float.valueOf(value.toString()).floatValue(); } else if (value instanceof String) {
} return Double.valueOf(value.toString()).doubleValue();
if (value instanceof String) {
return Float.valueOf(value.toString()).floatValue();
} else { } 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); 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) @Test(timeout = 10000)
public void testGetString() throws JMSException { public void testGetString() throws JMSException {
ActiveMQMapMessage msg = new ActiveMQMapMessage(); ActiveMQMapMessage msg = new ActiveMQMapMessage();