MessagingConnectionService implements ConnectionListener { public void notifyMissionMessageReceivers(Message message) { try { for (MessageReceiver receiver : missionMessageReceivers) { switch (message.getPayloadType()) { case AssignMission: receiver.onAssignMissionMessageReceived((AssignMissionMessage) message); break; case FinalAssignMission: receiver.onFinalAssignMissionMessageReceived((FinalAssignMissionMessage) message); break; } } } catch (ClassCastException e) { Log.d("Error", "Could not cast to" + message.getPayloadType(), e); } } @Inject  MessagingConnectionService(); void connect(); void disconnect(); void addConnectionListener(MessagingConnectionListener listener); void removeConnectionListener(MessagingConnectionListener listener); void addMissionMessageReceiver(MessageReceiver listener); void removeMissionMessageReceiver(MessageReceiver listener); void addDroneAttributeUpdateReceiver(DroneAttributeUpdateReceiver droneAttributesUpdateListener); void removeDroneAttributeUpdateReceiver(DroneAttributeUpdateReceiver droneAttributesUpdateListener); void notifyMissionMessageReceivers(Message message); void notifyDroneAttributeMessageReceivers(Message message); void sendMessage(String message); @Override void onChannelRecovery(Connection connection); @Override void onCreate(Connection connection); @Override void onCreateFailure(Throwable failure); @Override void onRecovery(Connection connection); @Override void onRecoveryFailure(Connection connection, Throwable failure); void setServerIP(String serverIP); void setIsLocalConnection(boolean localConnection); void setRabbitMqUser(String rabbitMqUser); void setRabbitMqPassword(String rabbitMqPassword); MissionDto getCurrentMission(); void setCurrentMission(MissionDto currentMission); String getRabbitMqServerAddress(); void setDroneToken(String droneToken); ConnectionState getConnectionState();  }
@Test public void assignMissionMessageReceivingTest() { AssignMissionMessage assignMissionMessage = new AssignMissionMessage(); MissionDto mission = new MissionDto(); assignMissionMessage.setMission(mission); String messageStr = messageConverter.parseMessageToString(assignMissionMessage); JsonBasedMessageConverter jsonBasedMessageConverter = new JsonBasedMessageConverter(); Message message = jsonBasedMessageConverter.parseStringToMessage(messageStr); service.notifyMissionMessageReceivers(message); verify(messageReceiver).onAssignMissionMessageReceived(assignMissionMessage); }
@Test public void finalAssignMissionMessageReceivingTest() { FinalAssignMissionMessage finalAssignMissionMessage = new FinalAssignMissionMessage(); MissionDto mission = new MissionDto(); finalAssignMissionMessage.setMission(mission); String messageStr = messageConverter.parseMessageToString(finalAssignMissionMessage); JsonBasedMessageConverter jsonBasedMessageConverter = new JsonBasedMessageConverter(); Message message = jsonBasedMessageConverter.parseStringToMessage(messageStr); service.notifyMissionMessageReceivers(message); verify(messageReceiver).onFinalAssignMissionMessageReceived(finalAssignMissionMessage); }