@Test
  public void testIsPortAvailable() throws IOException {
    socket = new ServerSocket();
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    socket.bind(new InetSocketAddress(getLoopback(), port));

    assertFalse(AvailablePort.isPortAvailable(port, AvailablePort.SOCKET,
        InetAddress.getByName(LOOPBACK_ADDRESS)));

    InetAddress localHostAddress = InetAddress.getLocalHost();
    // The next assertion assumes that the local host address is not a loopback address. Skip the
    // assertion on host machines that don't satisfy the assumption.
    if (!localHostAddress.isLoopbackAddress()) {
      assertTrue(AvailablePort.isPortAvailable(port, AvailablePort.SOCKET, localHostAddress));
    }

    // This should test all interfaces.
    assertFalse(AvailablePort.isPortAvailable(port, AvailablePort.SOCKET));
  }
multicast availability is tested in JGroupsMessengerJUnitTest
geode-core/src/integrationTest/java/org/apache/geode/internal/AvailablePortJUnitTest.java