@Override
  protected ResourceConfig configure() {
    // Enable TestContainer to not start at default port if it's already in use
    forceSet(TestProperties.CONTAINER_PORT, getPort(8079)+"");
    return new ResourceConfig().packages("com.example"); // replace with your package
  }
Makes JerseyTest use random port in case default one is unavailable.
ambari-server/src/test/java/org/apache/ambari/server/RandomPortJerseyTest.java