Search in sources :

Example 1 with IConnectionChangeListener

use of games.strategy.net.IConnectionChangeListener in project triplea by triplea-game.

the class RemoteMessengerTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    // simple set up for non networked testing
    final List<IConnectionChangeListener> connectionListeners = new CopyOnWriteArrayList<>();
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(final InvocationOnMock invocation) {
            connectionListeners.add(invocation.getArgument(0));
            return null;
        }
    }).when(serverMessenger).addConnectionChangeListener(any());
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(final InvocationOnMock invocation) {
            for (final IConnectionChangeListener listener : connectionListeners) {
                listener.connectionRemoved(invocation.getArgument(0));
            }
            return null;
        }
    }).when(serverMessenger).removeConnection(any());
    final Node dummyNode = new Node("dummy", InetAddress.getLocalHost(), 0);
    when(serverMessenger.getLocalNode()).thenReturn(dummyNode);
    when(serverMessenger.getServerNode()).thenReturn(dummyNode);
    when(serverMessenger.isServer()).thenReturn(true);
    remoteMessenger = new RemoteMessenger(new UnifiedMessenger(serverMessenger));
}
Also used : RemoteMessenger(games.strategy.engine.message.RemoteMessenger) IConnectionChangeListener(games.strategy.net.IConnectionChangeListener) InvocationOnMock(org.mockito.invocation.InvocationOnMock) INode(games.strategy.net.INode) Node(games.strategy.net.Node) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

RemoteMessenger (games.strategy.engine.message.RemoteMessenger)1 IConnectionChangeListener (games.strategy.net.IConnectionChangeListener)1 INode (games.strategy.net.INode)1 Node (games.strategy.net.Node)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1