@Test public void shouldSendMessageToAParticularNode() throws Exception { when(lanNode.isConnected()).thenReturn(true); networkingService.sendTo(message, remoteAddress); verify(connection).write(anyString()); }
@Test public void shouldAddNode() throws Exception { when(lanNode.isConnected()).thenReturn(false, true); networkingService.onDiscoveredAddress(remoteAddress); verify(nodeFactory).newNode(remoteAddress); verify(lanNode).connect(); }
@Test public void shouldSendMessageToAllKnownNodes() throws Exception { networkingService.onDiscoveredAddress(remoteAddress); String otherAddress = "192.168.1.xxo"; networkingService.onDiscoveredAddress(otherAddress); when(lanNode.isConnected()).thenReturn(true); networkingService.send(message); verify(connection, times(2)).write(anyString()); }
@Before public void init() throws Exception { networkingService.start(); verify(discoveryService).addLanDiscoveryListener(networkingService); when(acceptor.isOpen()).thenReturn(true); networkingService.addMessageListener(listener); when(nodeFactory.newNode(anyString())).thenReturn(lanNode); when(localInetAddress.getHostAddress()).thenReturn(localAddress); when(lanNode.getConnection()).thenReturn(connection); when(connection.getLocalAddress()).thenReturn(localInetAddress); when(connection.getRemoteAddress()).thenReturn(remoteInetAddress); }