DestinationProvider { public Destination getDestination(final String destinationName) { try { return (Destination) initialContext.lookup(destinationName); } catch (final NamingException e) { throw new JmsEnvelopeSenderException(format("Exception while looking up JMS destination name '%s'", destinationName), e); } }  Destination getDestination(final String destinationName);  }
@Test public void shouldGetDestinationFromInitialContext() throws Exception { final String destinationName = "destination name"; final Destination destination = mock(Destination.class); when(initialContext.lookup(destinationName)).thenReturn(destination); assertThat(destinationProvider.getDestination(destinationName), is(destination)); }
@Test public void shouldThrowExceptionIfInitialContextThrowsNamingException() throws Exception { final NamingException namingException = new NamingException("Ooops"); final String destinationName = "destination name"; when(initialContext.lookup(destinationName)).thenThrow(namingException); try { destinationProvider.getDestination(destinationName); fail(); } catch (final JmsEnvelopeSenderException expected) { assertThat(expected.getCause(), is(namingException)); assertThat(expected.getMessage(), is("Exception while looking up JMS destination name 'destination name'")); } }