### Question:
NetUtils { static public boolean isEqual(String host1, String host2) { List<String> host1_ips = new ArrayList<String>(); List<String> host2_ips = new ArrayList<String>(); try { if (!StringUtils.ok(host1) && !StringUtils.ok(host2)) return true; if (!StringUtils.ok(host1) || !StringUtils.ok(host2)) return false; InetAddress[] adds1 = InetAddress.getAllByName(host1); InetAddress[] adds2 = InetAddress.getAllByName(host2); boolean adds1Empty = false; boolean adds2Empty = false; if (adds1.length <= 0) adds1Empty = true; if (adds2.length <= 0) adds2Empty = true; if (adds1Empty && adds2Empty) return true; if (adds1Empty || adds2Empty) return false; for (InetAddress ia : adds1) host1_ips.add(ia.getHostAddress()); for (InetAddress ia : adds2) host2_ips.add(ia.getHostAddress()); for (String h1ip : host1_ips) for (String h2ip : host2_ips) if (h1ip.equals(h2ip)) return true; return false; } catch (UnknownHostException ex) { return false; } } private  NetUtils(); static boolean isThisHostLocal(String hostname); static boolean isEqual(String host1, String host2); static Socket getClientSocket(final String host, final int port, final int msecTimeout); static String getHostName(); static String getCanonicalHostName(); static InetAddress[] getHostAddresses(); static String[] getHostIPs(); static String trimIP(String ip); static byte[] ip2bytes(String ip); static boolean isLocalHost(String ip); static boolean isLocal(String ip); static boolean isRemote(String ip); static int getNextFreePort(String hostName, int port); static int getFreePort(String hostName, int startingPort, int endingPort); static boolean isPortValid(int portNumber); static boolean isPortStringValid(String portNumber); static boolean isPortFree(String hostName, int portNumber); static PortAvailability checkPort(int portNumber); static boolean isPortFree(int portNumber); static int getFreePort(); static boolean isSecurePort(String hostname, int port); static boolean isRunning(String host, int port, int timeoutMilliseconds); static boolean isRunning(String host, int port); static final boolean isRunning(int port); static void main(String[] args); static final int MAX_PORT; }### Answer:
@Test public void testEquals() { assertTrue(NetUtils.isEqual(null, null)); assertTrue(NetUtils.isEqual(null, "")); assertTrue(NetUtils.isEqual("", "")); assertTrue(NetUtils.isEqual("localhost", "localhost")); assertFalse(NetUtils.isEqual(null, "localhost")); assertTrue(NetUtils.isEqual("localhost", "localhost")); }
@Test public void testEqualsSpecial() { if (SPECIAL && "bnevins".equals(System.getProperty("user.name"))) { String x1 = "unix"; String x2 = "improvident.sfbay"; String x3 = "improvident.sfbay.sun.com"; String x4 = "improvident.sfbay.sun"; assertTrue(NetUtils.isEqual(x1, x2)); assertTrue(NetUtils.isEqual(x1, x3)); assertTrue(NetUtils.isEqual(x2, x3)); assertTrue(NetUtils.isEqual(x1, x1)); assertTrue(NetUtils.isEqual(x2, x2)); assertTrue(NetUtils.isEqual(x3, x3)); assertFalse(NetUtils.isEqual(x4, x4)); assertFalse(NetUtils.isEqual(x1, x4)); assertFalse(NetUtils.isEqual(x2, x4)); assertFalse(NetUtils.isEqual(x3, x4)); assertFalse(NetUtils.isEqual(unlikelyName, unlikelyName)); } }