diff --git a/java/client/test/org/openqa/selenium/ReferrerTest.java b/java/client/test/org/openqa/selenium/ReferrerTest.java index 7f632b7652bef..585cffd37fd7c 100644 --- a/java/client/test/org/openqa/selenium/ReferrerTest.java +++ b/java/client/test/org/openqa/selenium/ReferrerTest.java @@ -32,6 +32,7 @@ import com.google.common.base.Charsets; import com.google.common.base.Joiner; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.net.HostAndPort; @@ -454,6 +455,7 @@ protected void after() { */ private abstract static class ServerResource extends ExternalResource { protected final Server server; + private HostAndPort hostAndPort; ServerResource() { server = new Server(); @@ -470,7 +472,7 @@ void addHandler(Handler handler) { } HostAndPort getHostAndPort() { - return HostAndPort.fromParts(server.getURI().getHost(), server.getURI().getPort()); + return Preconditions.checkNotNull(hostAndPort); } String getBaseUrl() { @@ -480,6 +482,7 @@ String getBaseUrl() { void start() { try { server.start(); + hostAndPort = HostAndPort.fromParts(server.getURI().getHost(), server.getURI().getPort()); new UrlChecker().waitUntilAvailable(10, TimeUnit.SECONDS, new URL(getBaseUrl())); } catch (Exception e) { throw new RuntimeException(e);