@Test
public void testSendMessageSafely_theMessageIsStoredWhenTheMachineIsNotThere() throws Exception {

	TestApplication app = new TestApplication();
	ManagedApplication ma = new ManagedApplication( app );
	Message msg = new MsgCmdRemoveInstance( "/" );
	List<InstanceStatus> statuses = new ArrayList<>( Arrays.asList( InstanceStatus.values()));
	statuses.remove( InstanceStatus.DEPLOYED_STARTED );
	Mockito.when( this.msgClient.isConnected()).thenReturn( true );
	for( InstanceStatus status : statuses ) {
		Mockito.reset( this.msgClient );
		ma.removeAwaitingMessages( app.getMySqlVm());
		app.getMySqlVm().setStatus( status );
		Mockito.verifyZeroInteractions( this.msgClient );
		this.mngr.sendMessageSafely( ma, app.getMySqlVm(), msg );
		Mockito.verify( this.msgClient, Mockito.times( 1 )).isConnected();
		Mockito.verify( this.msgClient, Mockito.times( 0 )).sendMessageToAgent(
				Mockito.any( Application.class ),
				Mockito.any( Instance.class ),
				Mockito.any( Message.class ));
		List<Message> messages = ma.removeAwaitingMessages( app.getMySqlVm());
		Assert.assertEquals( 1, messages.size());
		Assert.assertEquals( msg, messages.iterator().next());
	}
}