### Question:
JmsContext implements JMSContext, AutoCloseable { @Override public synchronized void close() { JMSRuntimeException failure = null; try { if (session != null) { session.close(); } } catch (JMSException jmse) { failure = JmsExceptionSupport.createRuntimeException(jmse); } if (connectionRefCount.decrementAndGet() == 0) { try { connection.close(); } catch (JMSException jmse) { if (failure == null) { failure = JmsExceptionSupport.createRuntimeException(jmse); } } } if (failure != null) { throw failure; } } JmsContext(JmsConnection connection, int sessionMode); private  JmsContext(JmsConnection connection, int sessionMode, AtomicLong connectionRefCount); @Override void start(); @Override void stop(); @Override synchronized void close(); @Override void acknowledge(); @Override void commit(); @Override void rollback(); @Override void recover(); @Override void unsubscribe(String name); @Override BytesMessage createBytesMessage(); @Override MapMessage createMapMessage(); @Override Message createMessage(); @Override ObjectMessage createObjectMessage(); @Override ObjectMessage createObjectMessage(Serializable object); @Override StreamMessage createStreamMessage(); @Override TextMessage createTextMessage(); @Override TextMessage createTextMessage(String text); @Override Queue createQueue(String queueName); @Override Topic createTopic(String topicName); @Override TemporaryQueue createTemporaryQueue(); @Override TemporaryTopic createTemporaryTopic(); @Override synchronized JMSContext createContext(int sessionMode); @Override JMSProducer createProducer(); @Override JMSConsumer createConsumer(Destination destination); @Override JMSConsumer createConsumer(Destination destination, String selector); @Override JMSConsumer createConsumer(Destination destination, String selector, boolean noLocal); @Override JMSConsumer createDurableConsumer(Topic topic, String name); @Override JMSConsumer createDurableConsumer(Topic topic, String name, String selector, boolean noLocal); @Override JMSConsumer createSharedConsumer(Topic topic, String name); @Override JMSConsumer createSharedConsumer(Topic topic, String name, String selector); @Override JMSConsumer createSharedDurableConsumer(Topic topic, String name); @Override JMSConsumer createSharedDurableConsumer(Topic topic, String name, String selector); @Override QueueBrowser createBrowser(Queue queue); @Override QueueBrowser createBrowser(Queue queue, String selector); @Override boolean getAutoStart(); @Override void setAutoStart(boolean autoStart); @Override String getClientID(); @Override void setClientID(String clientID); @Override ExceptionListener getExceptionListener(); @Override void setExceptionListener(ExceptionListener listener); @Override ConnectionMetaData getMetaData(); @Override int getSessionMode(); @Override boolean getTransacted();  }### Answer:
@Test public void testRuntimeExceptionOnConnectionClose() throws JMSException { JmsConnection connection = Mockito.mock(JmsConnection.class); JmsSession session = Mockito.mock(JmsSession.class); Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session); JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE); Mockito.doThrow(IllegalStateException.class).when(connection).close(); try { context.close(); fail("Should throw ISRE"); } catch (IllegalStateRuntimeException isre) { } }