From c57f2674650fa6ada8bf7324493e550ecf00b0e1 Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Mon, 22 Apr 2013 10:19:43 +0000 Subject: QPID-4671 : merged to QPID-4659 branch git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/QPID-4659@1470430 13f79535-47bb-0310-9956-ffa450edef68 --- .../qpid/server/exchange/FanoutExchange.java | 7 ++- .../qpid/server/exchange/FanoutExchangeTest.java | 67 ++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/FanoutExchangeTest.java diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java index 8c433ce985..6ad5eb261e 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java @@ -76,7 +76,7 @@ public class FanoutExchange extends AbstractExchange public boolean isBound(AMQShortString routingKey, AMQQueue queue) { - return _queues.containsKey(queue); + return isBound(queue); } public boolean isBound(AMQShortString routingKey) @@ -87,7 +87,10 @@ public class FanoutExchange extends AbstractExchange public boolean isBound(AMQQueue queue) { - + if (queue == null) + { + return false; + } return _queues.containsKey(queue); } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/FanoutExchangeTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/FanoutExchangeTest.java new file mode 100644 index 0000000000..67739373e1 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/FanoutExchangeTest.java @@ -0,0 +1,67 @@ +package org.apache.qpid.server.exchange; + +import static org.mockito.Mockito.mock; + +import java.util.UUID; + +import junit.framework.TestCase; + +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.framing.FieldTable; +import org.apache.qpid.server.binding.Binding; +import org.apache.qpid.server.queue.AMQQueue; + +public class FanoutExchangeTest extends TestCase +{ + private FanoutExchange _exchange; + + public void setUp() + { + _exchange = new FanoutExchange(); + } + + public void testIsBoundAMQShortStringFieldTableAMQQueueWhenQueueIsNull() + { + assertFalse("calling isBound(AMQShortString,FieldTable,AMQQueue) with null queue should return false", + _exchange.isBound((AMQShortString) null, (FieldTable) null, (AMQQueue) null)); + } + + public void testIsBoundAMQShortStringAMQQueueWhenQueueIsNull() + { + assertFalse("calling isBound(AMQShortString,AMQQueue) with null queue should return false", + _exchange.isBound((AMQShortString) null, (AMQQueue) null)); + } + + public void testIsBoundAMQQueueWhenQueueIsNull() + { + assertFalse("calling isBound(AMQQueue) with null queue should return false", _exchange.isBound((AMQQueue) null)); + } + + public void testIsBoundAMQShortStringFieldTableAMQQueue() + { + AMQQueue queue = bindQueue(); + assertTrue("Should return true for a bound queue", + _exchange.isBound((AMQShortString) null, (FieldTable) null, queue)); + } + + public void testIsBoundAMQShortStringAMQQueue() + { + AMQQueue queue = bindQueue(); + assertTrue("Should return true for a bound queue", + _exchange.isBound((AMQShortString) null, queue)); + } + + public void testIsBoundAMQQueue() + { + AMQQueue queue = bindQueue(); + assertTrue("Should return true for a bound queue", + _exchange.isBound(queue)); + } + + private AMQQueue bindQueue() + { + AMQQueue queue = mock(AMQQueue.class); + _exchange.addBinding(new Binding(UUID.randomUUID(), "does not matter", queue, _exchange, null)); + return queue; + } +} -- cgit v1.2.1