### Question:
AmqpSubscriptionTracker { public String reserveNextSubscriptionLinkName(String subscriptionName, JmsConsumerInfo consumerInfo) { validateSubscriptionName(subscriptionName); if(consumerInfo == null) { throw new IllegalArgumentException("Consumer info must not be null."); } if (consumerInfo.isShared()) { if (consumerInfo.isDurable()) { return getSharedDurableSubLinkName(subscriptionName, consumerInfo); } else { return getSharedVolatileSubLinkName(subscriptionName, consumerInfo); } } else if (consumerInfo.isDurable()) { registerExclusiveDurableSub(subscriptionName); return subscriptionName; } else { throw new IllegalStateException("Non-shared non-durable sub link naming is not handled by the tracker."); } }  String reserveNextSubscriptionLinkName(String subscriptionName, JmsConsumerInfo consumerInfo); String getFirstDurableSubscriptionLinkName(String subscriptionName, boolean hasClientID); boolean isActiveExclusiveDurableSub(String subscriptionName); boolean isActiveSharedDurableSub(String subscriptionName); boolean isActiveDurableSub(String subscriptionName); boolean isActiveSharedVolatileSub(String subscriptionName); void consumerRemoved(JmsConsumerInfo consumerInfo);  }### Answer:
@Test public void testReserveNextSubscriptionLinkNameExceptions() { String topicName = "myTopic"; String subscriptionName1 = "mySubscription1"; AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker(); JmsConsumerInfo consumerInfo = createConsumerInfo(subscriptionName1, topicName, true, true, true); try { tracker.reserveNextSubscriptionLinkName(null, consumerInfo); fail("Should throw IAE on null subscription name"); } catch (IllegalArgumentException iae) {} try { tracker.reserveNextSubscriptionLinkName("", consumerInfo); fail("Should throw IAE on empty subscription name"); } catch (IllegalArgumentException iae) {} try { tracker.reserveNextSubscriptionLinkName("test" + SUB_NAME_DELIMITER, consumerInfo); fail("Should throw IAE on subscription name with delimiter"); } catch (IllegalArgumentException iae) {} try { tracker.reserveNextSubscriptionLinkName("test", null); fail("Should throw IAE on null Consumer Info"); } catch (IllegalArgumentException iae) {} }
@Test public void testReserveNextSubscriptionLinkNameSharedDurableWithNonMatchingTopic() { String topicName = "myTopic"; String subscriptionName1 = "mySubscription1"; AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker(); JmsConsumerInfo sub1consumer1 = createConsumerInfo(subscriptionName1, topicName, true, true, true); assertEquals("Unexpected first sub link name", subscriptionName1, tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer1)); JmsConsumerInfo sub1consumer2 = createConsumerInfo(subscriptionName1, topicName + "-Alt", true, true, true); try { tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer2); fail("Expected JMSRuntimeException when Topic doesn't match previous subscription"); } catch (JMSRuntimeException jmsre) { } }
@Test public void testReserveNextSubscriptionLinkNameSharedVolatileWithNonMatchingTopic() { String topicName = "myTopic"; String subscriptionName1 = "mySubscription1"; AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker(); JmsConsumerInfo sub1consumer1 = createConsumerInfo(subscriptionName1, topicName, true, false, true); assertEquals("Unexpected first sub link name", subscriptionName1 + SUB_NAME_DELIMITER + "volatile1", tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer1)); JmsConsumerInfo sub1consumer2 = createConsumerInfo(subscriptionName1, topicName + "-alt", true, false, true); try { tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer2); fail("Expected JMSRuntimeException when Topic doesn't match previous subscription"); } catch (JMSRuntimeException jmsre) { } }