MessageParser { @Nullable static String channelName(@Nullable Destination destination) { if (destination == null) return null; boolean isQueue = isQueue(destination); try { if (isQueue) { return ((Queue) destination).getQueueName(); } else { return ((Topic) destination).getTopicName(); } } catch (Throwable t) { propagateIfFatal(t); log(t, "error getting destination name from {0}", destination, null); } return null; }    }
@Test public void channelName_queueAndTopic_null() { assertThat(MessageParser.channelName(null)).isNull(); }
@Test public void channelName_queueAndTopic_queueOnQueueName() throws JMSException { QueueAndTopic destination = mock(QueueAndTopic.class); when(destination.getQueueName()).thenReturn("queue-foo"); assertThat(MessageParser.channelName(destination)) .isEqualTo("queue-foo"); }
@Test public void channelName_queueAndTopic_topicOnNoQueueName() throws JMSException { QueueAndTopic destination = mock(QueueAndTopic.class); when(destination.getTopicName()).thenReturn("topic-foo"); assertThat(MessageParser.channelName(destination)) .isEqualTo("topic-foo"); }