### Question:
NodeManager implements INodeManager { @Override public synchronized boolean joinNetwork(List<String> bootstrappingNodes) { boolean connected = false; Iterator<String> nodeIt = bootstrappingNodes.iterator(); while (nodeIt.hasNext() && !connected) { String node = nodeIt.next(); boolean res = false; try { res = joinNetwork(node); connected = isConnected(); if (res && connected) { logger.debug("Successfully connected to node {}", node); } else { logger.debug("Could not connect to node {}", node); } } catch(UnknownHostException e) { logger.warn("Address of host could not be determined: {}", node); res = false; connected = false; } } return connected; } @Inject  NodeManager(final MessageBus messageBus); @Override synchronized boolean joinNetwork(List<String> bootstrappingNodes); @Override synchronized boolean joinNetwork(final String address); @Override synchronized boolean createNetwork(); @Override synchronized boolean leaveNetwork(); @Override boolean isConnected(); @Override IH2HNode getNode(); @Override INetworkConfiguration getNetworkConfiguration(); @Override IFileConfiguration getFileConfiguration();  }### Answer:
@Test public void testJoinNetwork_Node_WrongAddress() throws UnknownHostException { initialNodeManager = createInitialNode(); boolean ret = nodeManager.joinNetwork("1.2.3.4"); assertFalse(ret); Mockito.verify(messageBus, Mockito.never()).publish(Mockito.anyObject()); }
@Test public void testJoinNetwork_Node_UnknownHost() { initialNodeManager = createInitialNode(); try { nodeManager.joinNetwork("unknownHost"); fail("Exception was not thrown, but was expected!"); } catch(UnknownHostException uhe) { } Mockito.verify(messageBus, Mockito.never()).publish(Mockito.anyObject()); }
@Test(expected = UnknownHostException.class) public void testJoinNetwork_UnknownHost() throws UnknownHostException { nodeManager.joinNetwork("unknownhost"); }
@Test public void testJoinNetwork_WrongAddress() throws UnknownHostException{ assertFalse(nodeManager.joinNetwork("1.2.3.4")); }
@Test public void testJoinNetwork_CorrectAddress() throws UnknownHostException { assertTrue(nodeManager.joinNetwork("localhost")); }