DebugMngrImpl implements IDebugMngr { @Override public boolean pingMessageQueue( String message ) { boolean sent = false; final MsgEcho sentMessage = new MsgEcho( message ); try { this.messagingMngr.sendMessageToTheDm( sentMessage ); sent = true; this.logger.fine( "Sent Echo message on debug queue. Message=" + message + ", UUID=" + sentMessage.getUuid()); } catch( IOException e ) { this.logger.fine( "No Echo message was sent on debug queue. An error occurred with the messaging." ); Utils.logException( this.logger, e ); } return sent; } DebugMngrImpl( IMessagingMngr messagingMngr, INotificationMngr notificationMngr ); @Override boolean pingMessageQueue( String message ); @Override int pingAgent( ManagedApplication app, Instance scopedInstance, String message ); @Override void notifyMsgEchoReceived( MsgEcho message );  }
@Test public void testSendPingMessageQueue_normal() throws Exception { Mockito.verifyZeroInteractions( this.messagingMngr ); Assert.assertTrue( this.mngr.pingMessageQueue( "TEST" )); ArgumentCaptor<Message> argument = ArgumentCaptor.forClass( Message.class ); Mockito.verify( this.messagingMngr, Mockito.times( 1 )).sendMessageToTheDm( argument.capture()); Message message = argument.getValue(); Assert.assertTrue( message instanceof MsgEcho ); MsgEcho echo = (MsgEcho) message; Assert.assertEquals( "TEST", echo.getContent()); }
@Test public void testSendPingMessageQueue_messagingException() throws Exception { Mockito.doThrow( new IOException( "for test" ) ).when( this.messagingMngr ).sendMessageToTheDm( Mockito.any( Message.class )); Mockito.verifyZeroInteractions( this.messagingMngr ); Assert.assertFalse( this.mngr.pingMessageQueue( "TEST" )); Mockito.verify( this.messagingMngr, Mockito.times( 1 )).sendMessageToTheDm( Mockito.any( Message.class )); }