@Test
public void testIsLocalAddress() throws Exception {

  // Test - local host is local address
  assertTrue(NetUtils.isLocalAddress(InetAddress.getLocalHost()));
  
  // Test - all addresses bound network interface is local address
  Enumeration<NetworkInterface> interfaces = NetworkInterface
      .getNetworkInterfaces();
  if (interfaces != null) { // Iterate through all network interfaces
    while (interfaces.hasMoreElements()) {
      NetworkInterface i = interfaces.nextElement();
      Enumeration<InetAddress> addrs = i.getInetAddresses();
      if (addrs == null) {
        continue;
      }
      // Iterate through all the addresses of a network interface
      while (addrs.hasMoreElements()) {
        InetAddress addr = addrs.nextElement();
        assertTrue(NetUtils.isLocalAddress(addr));
      }
    }
  }
  assertFalse(NetUtils.isLocalAddress(InetAddress.getByName("8.8.8.8")));
}