NetworkService implements NetworkConnectionListener { public boolean sendMessageToUser(final String message, final User user) { if (privateChatEnabled) { tcpNetworkService.sendMessageToUser(message, user); return udpSender.send(message, user.getIpAddress(), user.getPrivateChatPort()); } else { return false; } } NetworkService(final Controller controller, final Settings settings, final ErrorHandler errorHandler); void connect(); void disconnect(); ConnectionWorker getConnectionWorker(); boolean isConnectionWorkerAlive(); boolean isNetworkUp(); void registerNetworkConnectionListener(final NetworkConnectionListener listener); void registerMainChatMessageReceiverListener(final ReceiverListener listener); void registerPrivateChatReceiverListener(final ReceiverListener listener); boolean sendMessageToAllUsers(final String message); boolean sendMessageToUser(final String message, final User user); void checkNetwork(); @Override void networkWentDown(final boolean silent); @Override void beforeNetworkCameUp(); @Override void networkCameUp(final boolean silent);  }
@Test public void sendMessageToUserShouldNotSendMessageWhenPrivateChatDisabled() { when(settings.isNoPrivateChat()).thenReturn(true); final User user = new User("User", 111); final NetworkService networkService = new NetworkService(controller, settings, errorHandler); final boolean messageSent = networkService.sendMessageToUser("Nothing", user); assertFalse(messageSent); }