You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2014/02/12 18:04:41 UTC
svn commit: r1567682 -
/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java
Author: robbie
Date: Wed Feb 12 17:04:41 2014
New Revision: 1567682
URL: http://svn.apache.org/r1567682
Log:
QPIDJMS-9: add some missing testing around handling of missing properties
Modified:
qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java
Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java?rev=1567682&r1=1567681&r2=1567682&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java Wed Feb 12 17:04:41 2014
@@ -181,6 +181,47 @@ public class MessageImplTest extends Qpi
assertFalse(names.hasMoreElements());
}
+ /**
+ * When a property is not set, the behaviour of JMS specifies that it is equivalent to a null value,
+ * and the primitive property accessors should behave in the same fashion as <primitive>.valueOf(String).
+ * Test that this is the case.
+ */
+ @Test
+ public void testGetMissingPrimitivePropertyResultsInExpectedBehaviour() throws Exception
+ {
+ String propertyName = "does.not.exist";
+
+ //expect false from Boolean.valueOf(null).
+ assertFalse(_testMessage.getBooleanProperty(propertyName));
+
+ //expect an NFE from the primitive integral <type>.valueOf(null) conversions
+ assertGetMissingPropertyThrowsNumberFormatException(_testMessage, propertyName, Byte.class);
+ assertGetMissingPropertyThrowsNumberFormatException(_testMessage, propertyName, Short.class);
+ assertGetMissingPropertyThrowsNumberFormatException(_testMessage, propertyName, Integer.class);
+ assertGetMissingPropertyThrowsNumberFormatException(_testMessage, propertyName, Long.class);
+
+ //expect an NPE from the primitive floating point .valueOf(null) conversions
+ try
+ {
+ _testMessage.getFloatProperty(propertyName);
+ fail("expected NPE from Float.valueOf(null) was not thrown");
+ }
+ catch(NullPointerException npe)
+ {
+ //expected;
+ }
+
+ try
+ {
+ _testMessage.getDoubleProperty(propertyName);
+ fail("expected NPE from Double.valueOf(null) was not thrown");
+ }
+ catch(NullPointerException npe)
+ {
+ //expected;
+ }
+ }
+
@Test
public void testClearPropertiesEmptiesProperties() throws Exception
{
@@ -1640,6 +1681,22 @@ public class MessageImplTest extends Qpi
}
}
+ private void assertGetMissingPropertyThrowsNumberFormatException(MessageImpl<?> testMessage,
+ String propertyName,
+ Class<?> clazz) throws JMSException
+ {
+ try
+ {
+ getMessagePropertyUsingTypeMethod(testMessage, propertyName, clazz);
+
+ fail("expected exception to be thrown");
+ }
+ catch(NumberFormatException nfe)
+ {
+ //expected
+ }
+ }
+
private Object getMessagePropertyUsingTypeMethod(MessageImpl<?> testMessage, String propertyName, Class<?> clazz) throws JMSException
{
if(clazz == Boolean.class)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org