WebApp extends ServletModule { public InetSocketAddress getListenerAddress() { return checkNotNull(httpServer, "httpServer").getConnectorAddress(0); }  @Provides HttpServer2 httpServer(); InetSocketAddress getListenerAddress(); int port(); void stop(); void joinThread(); @Provides Configuration conf(); String name(); String wsName(); String[] getServePathSpecs(); String getRedirectPath(); @Override void configureServlets(); void route(HTTP method, String pathSpec,
                    Class<? extends Controller> cls, String action); void routeWithoutDefaultView(String pathSpec,
                    Class<? extends Controller> cls, String action); void route(String pathSpec, Class<? extends Controller> cls,
                    String action); void route(String pathSpec, Class<? extends Controller> cls); abstract void setup();  }
@Test public void testPortRanges() throws Exception { WebApp app = WebApps.$for("test", this).start(); String baseUrl = baseUrl(app); WebApp app1 = null; WebApp app2 = null; WebApp app3 = null; WebApp app4 = null; WebApp app5 = null; try { int port = ServerSocketUtil.waitForPort(48000, 60); assertEquals("foo", getContent(baseUrl +"test/foo").trim()); app1 = WebApps.$for("test", this).at(port).start(); assertEquals(port, app1.getListenerAddress().getPort()); app2 = WebApps.$for("test", this).at("0.0.0.0", port, true).start(); assertTrue(app2.getListenerAddress().getPort() > port); Configuration conf = new Configuration(); port = ServerSocketUtil.waitForPort(47000, 60); app3 = WebApps.$for("test", this).at(port).withPortRange(conf, "abc"). start(); assertEquals(port, app3.getListenerAddress().getPort()); ServerSocketUtil.waitForPort(46000, 60); conf.set("abc", "46000-46500"); app4 = WebApps.$for("test", this).at(port).withPortRange(conf, "abc"). start(); assertEquals(46000, app4.getListenerAddress().getPort()); app5 = WebApps.$for("test", this).withPortRange(conf, "abc").start(); assertTrue(app5.getListenerAddress().getPort() > 46000); } finally { stopWebApp(app); stopWebApp(app1); stopWebApp(app2); stopWebApp(app3); stopWebApp(app4); stopWebApp(app5); } }