### Question:
TopicExchange extends Exchange implements BindingsRegistryListener { @Override public BindingSet getBindingsForRoute(String routingKey) { if (routingKey.isEmpty()) { return BindingSet.emptySet(); } lock.readLock().lock(); try { BindingSet matchedBindingSet = new BindingSet(); fastTopicMatcher.matchingBindings(routingKey, subscribedPattern -> { BindingSet bindingSet = getBindingsRegistry().getBindingsForRoute(subscribedPattern); matchedBindingSet.add(bindingSet); }); return matchedBindingSet; } finally { lock.readLock().unlock(); } } TopicExchange(String exchangeName, BindingDao bindingDao); @Override BindingSet getBindingsForRoute(String routingKey); @Override void onBind(String routingKey); @Override void onUnbind(String routingKey, boolean isLastSubscriber); @Override void onRetrieveAllBindingsForExchange(String routingKey);  }### Answer:
@Test(dataProvider = "positiveTopicPairs", description = "Test positive topic matching") public void testPositiveSingleTopicMatching(String subscribedPattern, String publishedTopic) throws BrokerException, ValidationException { DbBackedQueueHandlerFactory factory = new DbBackedQueueHandlerFactory(null, new NullBrokerMetricManager(), new BrokerCoreConfiguration()); QueueHandler handler = factory.createNonDurableQueueHandler(subscribedPattern, false); topicExchange.bind(handler, subscribedPattern, FieldTable.EMPTY_TABLE); BindingSet bindingSet = topicExchange.getBindingsForRoute(publishedTopic); Collection<Binding> unfilteredBindings = bindingSet.getUnfilteredBindings(); Assert.assertEquals(unfilteredBindings.iterator().hasNext(), true, "No matches found."); Assert.assertEquals( unfilteredBindings.iterator().next().getQueue().getName(), subscribedPattern, "No matches found."); }
@Test(dataProvider = "negativeTopicPairs", description = "Test negative topic matching") public void testNegativeSingleTopicMatching(String subscribedPattern, String publishedTopic) throws BrokerException, ValidationException { DbBackedQueueHandlerFactory factory = new DbBackedQueueHandlerFactory(null, new NullBrokerMetricManager(), new BrokerCoreConfiguration()); QueueHandler handler = factory.createNonDurableQueueHandler(subscribedPattern, false); topicExchange.bind(handler, subscribedPattern, FieldTable.EMPTY_TABLE); BindingSet bindingSet = topicExchange.getBindingsForRoute(publishedTopic); Collection<Binding> unfilteredBindings = bindingSet.getUnfilteredBindings(); Assert.assertEquals(unfilteredBindings.iterator().hasNext(), false, "No topic should match"); }
@Test(dataProvider = "positiveTopicPairs", description = "Test topic removal") public void testTopicRemoval(String subscribedPattern, String publishedTopic) throws BrokerException, ValidationException { DbBackedQueueHandlerFactory factory = new DbBackedQueueHandlerFactory(null, new NullBrokerMetricManager(), new BrokerCoreConfiguration()); QueueHandler handler = factory.createNonDurableQueueHandler(subscribedPattern, false); Queue queue = handler.getUnmodifiableQueue(); topicExchange.bind(handler, subscribedPattern, FieldTable.EMPTY_TABLE); topicExchange.unbind(queue, subscribedPattern); BindingSet bindingSet = topicExchange.getBindingsForRoute(publishedTopic); Collection<Binding> unfilteredBindings = bindingSet.getUnfilteredBindings(); Assert.assertEquals(unfilteredBindings.iterator().hasNext(), false, "No topic should match"); }