public static int findAvailablePort ( int maxRetries ) { int retries = 0 ; int randomPort ; boolean portAvailable ; do { randomPort = randomPort ( ) ; portAvailable = isPortAvailable ( randomPort ) ; retries ++ ; } while ( retries <= maxRetries && ! portAvailable ) ; assumeTrue ( "no open port found" , portAvailable ) ; return randomPort ; }
Finds an available port .