Class TestPortUtil

java.lang.Object
org.openhab.core.test.TestPortUtil

@NonNullByDefault public final class TestPortUtil extends Object
TestPortUtil provides helper methods for working with ports in tests.
Author:
Henning Treu - Initial contribution, Wouter Born - Increase reusability
  • Method Details

    • findFreePort

      public static int findFreePort()
      Returns a free TCP/IP port number on localhost. Heavily inspired from org.eclipse.jdt.launching.SocketUtil (to avoid a dependency to JDT just because of this). Slightly improved with close() missing in JDT. And throws exception instead of returning -1.
      Returns:
      a free TCP/IP port number on localhost
      Throws:
      IllegalStateException - if unable to find a free port