JmxWrapperForMessagingClient implements IMessagingClient, MessagingApiMBean { public void unregisterService() { try { if( this.serviceReg != null ) { this.logger.finer( "Running in an OSGi environment. Trying to unregister a MBean for the messaging." ); this.serviceReg.unregister(); this.logger.finer( "Running in an OSGi environment. The MBean was unregistered." ); } } catch( Exception e ) { this.logger.severe( "A MBean could not be unregistered for the messaging." ); Utils.logException( this.logger, e ); } finally { this.serviceReg = null; } } JmxWrapperForMessagingClient( IMessagingClient messagingClient );   JmxWrapperForMessagingClient( IMessagingClient messagingClient, OsgiHelper osgiHelper ); void unregisterService(); boolean isDismissClient(); @Override synchronized void reset(); @Override String getId(); @Override synchronized long getFailedSendingCount(); @Override synchronized long getSentMessagesCount(); @Override synchronized long getTimestampOfLastSendingFailure(); @Override synchronized long getTimestampOfLastSentMessage(); @Override synchronized long getFailedReceptionCount(); @Override synchronized long getReceivedMessagesCount(); @Override synchronized long getTimestampOfLastReceptionFailure(); @Override synchronized long getTimestampOfLastReceivedMessage(); @Override void closeConnection(); @Override void openConnection(); @Override void deleteMessagingServerArtifacts( Application application ); @Override Map<String,String> getConfiguration(); @Override String getMessagingType(); @Override boolean isConnected(); @Override void subscribe( MessagingContext ctx ); @Override void unsubscribe( MessagingContext ctx ); @Override void setMessageQueue( RoboconfMessageQueue messageQueue ); @Override void publish( MessagingContext ctx, Message msg ); @Override void setOwnerProperties(
			RecipientKind ownerKind,
			String domain,
			String applicationName,
			String scopedInstancePath );  }
@Test public void testUnregister_noRegistration() { IMessagingClient messagingClient = Mockito.mock( IMessagingClient.class ); JmxWrapperForMessagingClient client = new JmxWrapperForMessagingClient( messagingClient ); Assert.assertNull( client.serviceReg ); client.unregisterService(); Assert.assertNull( client.serviceReg ); }
@Test @SuppressWarnings( "unchecked" ) public void testUnregister_withRegistration() { IMessagingClient messagingClient = Mockito.mock( IMessagingClient.class ); JmxWrapperForMessagingClient client = new JmxWrapperForMessagingClient( messagingClient ); ServiceRegistration<MessagingApiMBean> serviceReg = Mockito.mock( ServiceRegistration.class ); client.serviceReg = serviceReg; client.unregisterService(); Assert.assertNull( client.serviceReg ); Mockito.verify( serviceReg, Mockito.only()).unregister(); }
@Test @SuppressWarnings( "unchecked" ) public void testUnregister_withRegistration_withException() { IMessagingClient messagingClient = Mockito.mock( IMessagingClient.class ); JmxWrapperForMessagingClient client = new JmxWrapperForMessagingClient( messagingClient ); ServiceRegistration<MessagingApiMBean> serviceReg = Mockito.mock( ServiceRegistration.class ); Mockito.doThrow( new RuntimeException( "for test" )).when( serviceReg ).unregister(); client.serviceReg = serviceReg; client.unregisterService(); Assert.assertNull( client.serviceReg ); Mockito.verify( serviceReg, Mockito.only()).unregister(); }