### Question:
JmsDefaultUnresolvedDestinationTransformer implements JmsUnresolvedDestinationTransformer { @Override public JmsDestination transform(Destination destination) throws JMSException { String queueName = null; String topicName = null; if (destination instanceof Queue) { queueName = ((Queue) destination).getQueueName(); } if (destination instanceof Topic) { topicName = ((Topic) destination).getTopicName(); } if (queueName == null && topicName == null) { throw new JMSException("Unresolvable destination: Both queue and topic names are null: " + destination); } try { Method isQueueMethod = destination.getClass().getMethod("isQueue"); Method isTopicMethod = destination.getClass().getMethod("isTopic"); Boolean isQueue = (Boolean) isQueueMethod.invoke(destination); Boolean isTopic = (Boolean) isTopicMethod.invoke(destination); if (isQueue) { return new JmsQueue(queueName); } else if (isTopic) { return new JmsTopic(topicName); } else { throw new JMSException("Unresolvable destination: Neither Queue nor Topic: " + destination); } } catch (Exception e) { throw new JMSException("Unresolvable destination: " + e.getMessage() + ": " + destination); } }  @Override JmsDestination transform(Destination destination); @Override JmsDestination transform(String destination);  }### Answer:
@Test public void testTransformDestinationDestinationWithNoNameThrowsJMSEx() throws JMSException { Destination destination = Mockito.mock(Destination.class); try { transformer.transform(destination); fail("Should throw a JMSException here"); } catch (JMSException ex) { } }
@Test public void testTransformDestinationDestinationWithoutTypeThrowsJMSEx() throws JMSException { ForeignTopicAndQueue destination = new ForeignTopicAndQueue("destination"); destination.setTopic(false); destination.setQueue(false); try { transformer.transform(destination); fail("Should throw a JMSException here"); } catch (JMSException ex) { } }
@Test public void testTopicTypeIsDetectedFromComposite() throws JMSException { ForeignTopicAndQueue destination = new ForeignTopicAndQueue("destination"); destination.setQueue(false); JmsDestination result = transformer.transform(destination); assertNotNull(result); assertTrue(result instanceof JmsTopic); }
@Test public void testQueueTypeIsDetectedFromComposite() throws JMSException { ForeignTopicAndQueue destination = new ForeignTopicAndQueue("destination"); destination.setTopic(false); JmsDestination result = transformer.transform(destination); assertNotNull(result); assertTrue(result instanceof JmsQueue); }
@Test public void testTopicTypeIsDetectedFromCompositeMisMatchedNameAndType() throws JMSException { ForeignTopicAndQueue destination = new ForeignTopicAndQueue("destination"); destination.setQueue(false); destination.setReturnTopicName(false); JmsDestination result = transformer.transform(destination); assertNotNull(result); assertTrue(result instanceof JmsTopic); }
@Test public void testQueueTypeIsDetectedFromCompositeMisMatchedNameAndType() throws JMSException { ForeignTopicAndQueue destination = new ForeignTopicAndQueue("destination"); destination.setTopic(false); destination.setReturnQueueName(false); JmsDestination result = transformer.transform(destination); assertNotNull(result); assertTrue(result instanceof JmsQueue); }
@Test public void testTransformStringAlwaysAnswersQueue() throws JMSException { JmsDestination destination = transformer.transform("test"); assertNotNull(destination); assertTrue(destination instanceof JmsQueue); }
@Test(expected=JMSException.class) public void testTransformStringWithNullThrowsJMSEx() throws JMSException { transformer.transform((String) null); }