ReconfigurableClient implements IClient, MessagingClientFactoryListener { static void terminateClient( IMessagingClient client, String errorMessage, Logger logger ) { try { logger.fine( "The reconfigurable client is requesting its internal connection to be closed." ); if( client != null ) client.closeConnection(); } catch( Exception e ) { logger.warning( errorMessage + " " + e.getMessage()); Utils.logException( logger, e ); } finally { if( client instanceof JmxWrapperForMessagingClient ) ((JmxWrapperForMessagingClient) client).unregisterService(); } } protected  ReconfigurableClient(); @Override void setDomain( String domain ); @Override String getDomain(); synchronized MessagingClientFactoryRegistry getRegistry(); synchronized void setRegistry( MessagingClientFactoryRegistry registry ); static MessagingClientFactoryRegistry lookupMessagingClientFactoryRegistryService( OsgiHelper osgiHelper ); @Override synchronized String getMessagingType(); void switchMessagingType( String factoryName ); @Override void addMessagingClientFactory( final IMessagingClientFactory factory ); @Override void removeMessagingClientFactory( IMessagingClientFactory factory ); @Override Map<String,String> getConfiguration(); abstract RecipientKind getOwnerKind(); void associateMessageProcessor( AbstractMessageProcessor<T> messageProcessor ); AbstractMessageProcessor<T> getMessageProcessor(); synchronized boolean hasValidClient(); IMessagingClient getMessagingClient();  }
@Test public void testTerminateClient_1() throws Exception { Logger logger = Logger.getLogger( getClass().getName()); IMessagingClient client = Mockito.mock( IMessagingClient.class ); ReconfigurableClient.terminateClient( client, "", logger ); Mockito.verify( client, Mockito.only()).closeConnection(); }
@Test public void testTerminateClient_2() throws Exception { Logger logger = Logger.getLogger( getClass().getName()); JmxWrapperForMessagingClient client = Mockito.mock( JmxWrapperForMessagingClient.class ); ReconfigurableClient.terminateClient( client, "", logger ); Mockito.verify( client ).closeConnection(); Mockito.verify( client ).unregisterService();; Mockito.verifyNoMoreInteractions( client ); }
@Test public void testTerminateClient_3() throws Exception { Logger logger = Logger.getLogger( getClass().getName()); JmxWrapperForMessagingClient client = Mockito.mock( JmxWrapperForMessagingClient.class ); Mockito.doThrow( new IOException( "for test" )).when( client ).closeConnection(); ReconfigurableClient.terminateClient( client, "", logger ); Mockito.verify( client ).closeConnection(); Mockito.verify( client ).unregisterService();; Mockito.verifyNoMoreInteractions( client ); }