NmapUtil { public Map<String, Boolean> getNodeListWithStatus() { Map<String, Boolean> result = new HashMap<String, Boolean>(); if ((nodePattern != null) && !nodePattern.isEmpty() && !nodePattern.equals(Constant.Strings.SPACE)) { String[] splittedNodeArray = this.nodePattern .split(Constant.Strings.SPACE); Boolean isReachable = false; for (String host : splittedNodeArray) { try { isReachable = InetAddress.getByName(host.trim()) .isReachable(3000); result.put(host.trim(), isReachable); } catch (Exception e) { logger.error(e.getMessage(), e); } } } return result; } NmapUtil(String nodePattern); Map<String, Boolean> getNodeListWithStatus(); Map<String, String> getHostIPMap(List<String> hostNameList);  }
@Test public void testNmapUtil_1() { NmapUtil fixture = new NmapUtil(null); Map<String, Boolean> result = null; try { result = fixture.getNodeListWithStatus(); } catch (Exception e) { e.printStackTrace(); } assertNotNull(fixture); assertNotNull(result); assertEquals(0, result.size()); }
@Test public void testNmapUtil_2() { String nodePattern = "127.0.0.1"; NmapUtil fixture = new NmapUtil(nodePattern); Map<String, Boolean> result = null; try { result = fixture.getNodeListWithStatus(); } catch (Exception e) { e.printStackTrace(); } assertNotNull(fixture); assertNotNull(result); assertEquals(1, result.size()); assertTrue(result.get(result.keySet().iterator().next())); }