You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2016/09/19 20:03:24 UTC

[1/3] qpid-jms git commit: QPIDJMS-207 Add additional tests for exception handlers

Repository: qpid-jms
Updated Branches:
  refs/heads/master 790198118 -> 6eac59222


QPIDJMS-207 Add additional tests for exception handlers

Test that the session handles throwing the right error on use of invalid
temporary destination values. 

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/bc7ef644
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/bc7ef644
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/bc7ef644

Branch: refs/heads/master
Commit: bc7ef64495e2b4ba09979b830c0dd37f46b210bd
Parents: 7901981
Author: Timothy Bish <ta...@gmail.com>
Authored: Mon Sep 19 12:48:22 2016 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Mon Sep 19 12:48:22 2016 -0400

----------------------------------------------------------------------
 .../apache/qpid/jms/session/JmsSessionTest.java | 37 ++++++++++++++++++++
 1 file changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/bc7ef644/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionTest.java
index 531828a..c4f78d4 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionTest.java
@@ -21,18 +21,24 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.UUID;
 
 import javax.jms.IllegalStateException;
 import javax.jms.InvalidDestinationException;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
 import javax.jms.ObjectMessage;
 import javax.jms.Session;
+import javax.jms.TemporaryQueue;
 import javax.jms.TextMessage;
 
 import org.apache.qpid.jms.JmsConnectionTestSupport;
 import org.apache.qpid.jms.JmsSession;
+import org.apache.qpid.jms.JmsTemporaryQueue;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -266,4 +272,35 @@ public class JmsSessionTest extends JmsConnectionTestSupport {
         JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
         session.createDurableConsumer(null, "name", "a > b", true);
     }
+
+    @Test(timeout = 10000)
+    public void testCannotCreateConsumerOnTempDestinationFromSomeOtherSource() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        TemporaryQueue tempQueue = new JmsTemporaryQueue("ID:" + UUID.randomUUID().toString());
+
+        try {
+            session.createConsumer(tempQueue);
+            fail("Should not be able to create a consumer");
+        } catch (InvalidDestinationException idex) {}
+    }
+
+    @Test//(timeout = 10000)
+    public void testCannotCreateConsumerOnDeletedTemporaryDestination() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        TemporaryQueue tempQueue = session.createTemporaryQueue();
+        MessageProducer producer = session.createProducer(tempQueue);
+
+        try {
+            producer.send(session.createMessage());
+        } catch (Exception ex) {
+            fail("Should be able to send to this temporary destination");
+        }
+
+        tempQueue.delete();
+
+        try {
+            producer.send(session.createMessage());
+            fail("Should not be able to send to this temporary destination");
+        } catch (IllegalStateException ise) {}
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[3/3] qpid-jms git commit: QPIDJMS-207 Add tests to validate Exception handling paths

Posted by ta...@apache.org.
QPIDJMS-207 Add tests to validate Exception handling paths

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/6eac5922
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/6eac5922
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/6eac5922

Branch: refs/heads/master
Commit: 6eac592221d514a7db53713fcfb6cafdb26f79cd
Parents: fcc6710
Author: Timothy Bish <ta...@gmail.com>
Authored: Mon Sep 19 16:02:47 2016 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Mon Sep 19 16:02:47 2016 -0400

----------------------------------------------------------------------
 .../qpid/jms/producer/JmsProducerTest.java      | 116 +++++++++++++++++++
 1 file changed, 116 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6eac5922/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
index 1bf4a08..457b51e 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
@@ -34,22 +34,27 @@ import java.util.UUID;
 import javax.jms.CompletionListener;
 import javax.jms.DeliveryMode;
 import javax.jms.Destination;
+import javax.jms.IllegalStateException;
+import javax.jms.IllegalStateRuntimeException;
 import javax.jms.JMSException;
 import javax.jms.JMSProducer;
 import javax.jms.Message;
 import javax.jms.MessageFormatRuntimeException;
+import javax.jms.Queue;
 
 import org.apache.qpid.jms.JmsConnectionTestSupport;
 import org.apache.qpid.jms.JmsContext;
 import org.apache.qpid.jms.JmsMessageProducer;
 import org.apache.qpid.jms.JmsProducer;
 import org.apache.qpid.jms.JmsSession;
+import org.apache.qpid.jms.JmsTemporaryQueue;
 import org.apache.qpid.jms.JmsTopic;
 import org.apache.qpid.jms.message.JmsMessage;
 import org.apache.qpid.jms.message.JmsOutboundMessageDispatch;
 import org.apache.qpid.jms.provider.mock.MockRemotePeer;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.Matchers;
 import org.mockito.Mockito;
 
 /**
@@ -1148,6 +1153,117 @@ public class JmsProducerTest extends JmsConnectionTestSupport {
         assertEquals(bodyValue, message.getBody(UUID.class));
     }
 
+    //----- Test for conversions to JMSRuntimeException ----------------------//
+
+    @Test
+    public void testRuntimeExceptionFromSendMessage() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);
+        Message message = Mockito.mock(Message.class);
+
+        Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
+        Mockito.when(session.createMessage()).thenReturn(message);
+
+        Mockito.doThrow(IllegalStateException.class).when(message).setJMSCorrelationID(Matchers.anyString());
+
+        JmsProducer producer = new JmsProducer(session, messageProducer);
+
+        producer.setJMSCorrelationID("id");
+
+        try {
+            producer.send(session.createTemporaryQueue(), session.createMessage());
+            fail("Should have thrown an exception");
+        } catch (IllegalStateRuntimeException isre) {}
+    }
+
+    @Test
+    public void testRuntimeExceptionFromSendByteBody() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);
+
+        Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
+        Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));
+
+        Mockito.doThrow(IllegalStateException.class).when(session).createBytesMessage();
+
+        JmsProducer producer = new JmsProducer(session, messageProducer);
+
+        try {
+            producer.send(session.createTemporaryQueue(), new byte[0]);
+            fail("Should have thrown an exception");
+        } catch (IllegalStateRuntimeException isre) {}
+    }
+
+    @Test
+    public void testRuntimeExceptionFromSendMapBody() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);
+
+        Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
+        Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));
+
+        Mockito.doThrow(IllegalStateException.class).when(session).createMapMessage();
+
+        JmsProducer producer = new JmsProducer(session, messageProducer);
+
+        try {
+            producer.send(session.createTemporaryQueue(), Collections.<String, Object>emptyMap());
+            fail("Should have thrown an exception");
+        } catch (IllegalStateRuntimeException isre) {}
+    }
+
+    @Test
+    public void testRuntimeExceptionFromSendSerializableBody() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);
+
+        Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
+        Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));
+
+        Mockito.doThrow(IllegalStateException.class).when(session).createObjectMessage();
+
+        JmsProducer producer = new JmsProducer(session, messageProducer);
+
+        try {
+            producer.send(session.createTemporaryQueue(), UUID.randomUUID());
+            fail("Should have thrown an exception");
+        } catch (IllegalStateRuntimeException isre) {}
+    }
+
+    @Test
+    public void testRuntimeExceptionFromSendStringBody() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);
+
+        Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
+        Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));
+
+        Mockito.doThrow(IllegalStateException.class).when(session).createTextMessage(Matchers.anyString());
+
+        JmsProducer producer = new JmsProducer(session, messageProducer);
+
+        try {
+            producer.send(session.createTemporaryQueue(), "test");
+            fail("Should have thrown an exception");
+        } catch (IllegalStateRuntimeException isre) {}
+    }
+
+    @Test
+    public void testRuntimeExceptionFromSetJMSReplyTo() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);
+        Queue queue = Mockito.mock(Queue.class);
+
+        Mockito.doThrow(IllegalStateException.class).when(queue).getQueueName();
+
+        JmsProducer producer = new JmsProducer(session, messageProducer);
+
+        try {
+            producer.setJMSReplyTo(queue);
+            fail("Should have thrown an exception");
+        } catch (IllegalStateRuntimeException isre) {}
+    }
+
     //----- Internal Support -------------------------------------------------//
 
     private void sendWithBodyOfType(JMSProducer producer, Class<?> asType) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[2/3] qpid-jms git commit: QPIDJMS-207 Test for the JMSConsumer implementation

Posted by ta...@apache.org.
QPIDJMS-207 Test for the JMSConsumer implementation

Tests that the JMSConsumer implementation passes most calls through to
the underlying consumer and that the methods convert to valid
JMSRuntimeException instances. 

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/fcc67101
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/fcc67101
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/fcc67101

Branch: refs/heads/master
Commit: fcc671015006de49dfb7b65cec757940cfbc202e
Parents: bc7ef64
Author: Timothy Bish <ta...@gmail.com>
Authored: Mon Sep 19 15:00:23 2016 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Mon Sep 19 15:00:23 2016 -0400

----------------------------------------------------------------------
 .../qpid/jms/consumer/JmsConsumerTest.java      | 344 +++++++++++++++++++
 1 file changed, 344 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/fcc67101/qpid-jms-client/src/test/java/org/apache/qpid/jms/consumer/JmsConsumerTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/consumer/JmsConsumerTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/consumer/JmsConsumerTest.java
new file mode 100644
index 0000000..4438c78
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/consumer/JmsConsumerTest.java
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.qpid.jms.consumer;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.util.Map;
+
+import javax.jms.IllegalStateException;
+import javax.jms.IllegalStateRuntimeException;
+import javax.jms.JMSException;
+
+import org.apache.qpid.jms.JmsConnectionTestSupport;
+import org.apache.qpid.jms.JmsConsumer;
+import org.apache.qpid.jms.JmsMessageConsumer;
+import org.apache.qpid.jms.JmsSession;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+
+/**
+ * Test for basic behavior of the JMSConsumer implementation.
+ */
+public class JmsConsumerTest extends JmsConnectionTestSupport {
+
+    @Test
+    public void testGetMessageSelector() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        try {
+            assertNull(consumer.getMessageSelector());
+        } finally {
+            consumer.close();
+        }
+
+        Mockito.verify(messageConsumer, Mockito.times(1)).getMessageSelector();
+    }
+
+    @Test
+    public void testGetMessageListener() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        try {
+            assertNull(consumer.getMessageListener());
+        } finally {
+            consumer.close();
+        }
+
+        Mockito.verify(messageConsumer, Mockito.times(1)).getMessageListener();
+    }
+
+    @Test
+    public void testReceivePassthrough() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        try {
+            assertNull(consumer.receive());
+        } finally {
+            consumer.close();
+        }
+
+        Mockito.verify(messageConsumer, Mockito.times(1)).receive();
+    }
+
+    @Test
+    public void testTimedReceivePassthrough() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        try {
+            assertNull(consumer.receive(100));
+        } finally {
+            consumer.close();
+        }
+
+        Mockito.verify(messageConsumer, Mockito.times(1)).receive(Matchers.anyInt());
+    }
+
+    @Test
+    public void testReceiveNoWaitPassthrough() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        try {
+            assertNull(consumer.receiveNoWait());
+        } finally {
+            consumer.close();
+        }
+
+        Mockito.verify(messageConsumer, Mockito.times(1)).receiveNoWait();
+    }
+
+    @Test
+    public void testReceiveBodyPassthrough() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        try {
+            assertNull(consumer.receiveBody(Map.class));
+        } finally {
+            consumer.close();
+        }
+
+        Mockito.verify(messageConsumer, Mockito.times(1)).receiveBody(Map.class, -1);
+    }
+
+    @Test
+    public void testTimedReceiveBodyPassthrough() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        try {
+            assertNull(consumer.receiveBody(Map.class, 100));
+        } finally {
+            consumer.close();
+        }
+
+        Mockito.verify(messageConsumer, Mockito.times(1)).receiveBody(Map.class, 100);
+    }
+
+    @Test
+    public void testNoWaitReceiveBodyPassthrough() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        try {
+            assertNull(consumer.receiveBodyNoWait(Map.class));
+        } finally {
+            consumer.close();
+        }
+
+        Mockito.verify(messageConsumer, Mockito.times(1)).receiveBody(Map.class, 0);
+    }
+
+    //----- Test Receive calls map zero to infinite wait ---------------------//
+
+    @Test
+    public void testReceiveBodyWithTimeoutZeroWaitsForever() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        consumer.receiveBody(Map.class, 0);
+        consumer.close();
+
+        Mockito.verify(messageConsumer).receiveBody(Map.class, -1);
+    }
+
+    //----- Test that the JMSRuntimeException retains error context ----------//
+
+    @Test
+    public void testRuntimeExceptionOnClose() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        Mockito.doThrow(IllegalStateException.class).when(messageConsumer).close();
+
+        try {
+            consumer.close();
+            fail("Should throw ISRE");
+        } catch (IllegalStateRuntimeException isre) {
+        }
+    }
+
+    @Test
+    public void testRuntimeExceptionOnGetMessageListener() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        Mockito.doThrow(IllegalStateException.class).when(messageConsumer).getMessageListener();
+
+        try {
+            consumer.getMessageListener();
+            fail("Should throw ISRE");
+        } catch (IllegalStateRuntimeException isre) {
+        } finally {
+            consumer.close();
+        }
+    }
+
+    @Test
+    public void testRuntimeExceptionOnSetMessageListener() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        Mockito.doThrow(IllegalStateException.class).when(messageConsumer).setMessageListener(null);
+
+        try {
+            consumer.setMessageListener(null);
+            fail("Should throw ISRE");
+        } catch (IllegalStateRuntimeException isre) {
+        } finally {
+            consumer.close();
+        }
+    }
+
+    @Test
+    public void testRuntimeExceptionOnGetMessageSelector() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        Mockito.doThrow(IllegalStateException.class).when(messageConsumer).getMessageSelector();
+
+        try {
+            consumer.getMessageSelector();
+            fail("Should throw ISRE");
+        } catch (IllegalStateRuntimeException isre) {
+        } finally {
+            consumer.close();
+        }
+    }
+
+    @Test
+    public void testRuntimeExceptionOnReceive() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receive();
+
+        try {
+            consumer.receive();
+            fail("Should throw ISRE");
+        } catch (IllegalStateRuntimeException isre) {
+        } finally {
+            consumer.close();
+        }
+    }
+
+    @Test
+    public void testRuntimeExceptionOnReceiveNoWait() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receiveNoWait();
+
+        try {
+            consumer.receiveNoWait();
+            fail("Should throw ISRE");
+        } catch (IllegalStateRuntimeException isre) {
+        } finally {
+            consumer.close();
+        }
+    }
+
+    @Test
+    public void testRuntimeExceptionOnTimedReceive() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receive(Matchers.anyInt());
+
+        try {
+            consumer.receive(100);
+            fail("Should throw ISRE");
+        } catch (IllegalStateRuntimeException isre) {
+        } finally {
+            consumer.close();
+        }
+    }
+
+    @Test
+    public void testRuntimeExceptionOnReceiveBody() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receiveBody(Map.class, -1);
+
+        try {
+            consumer.receiveBody(Map.class);
+            fail("Should throw ISRE");
+        } catch (IllegalStateRuntimeException isre) {
+        } finally {
+            consumer.close();
+        }
+    }
+
+    @Test
+    public void testRuntimeExceptionOnTimedReceiveBody() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receiveBody(Map.class, 100);
+
+        try {
+            consumer.receiveBody(Map.class, 100);
+            fail("Should throw ISRE");
+        } catch (IllegalStateRuntimeException isre) {
+        } finally {
+            consumer.close();
+        }
+    }
+
+    @Test
+    public void testRuntimeExceptionOnReceiveBodyNoWait() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
+        JmsConsumer consumer = new JmsConsumer(session, messageConsumer);
+
+        Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receiveBody(Map.class, 0);
+
+        try {
+            consumer.receiveBodyNoWait(Map.class);
+            fail("Should throw ISRE");
+        } catch (IllegalStateRuntimeException isre) {
+        } finally {
+            consumer.close();
+        }
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org