ServerSocketService extends AbstractExecutionThreadService { public int getPort() { awaitRunning(); checkState(serverSocket != null, "Socket has not been opened yet"); return serverSocket.getLocalPort(); } @Inject  ServerSocketService(CaliperOptions caliperOptions); int getPort(); ListenableFuture<OpenedSocket> getConnection(UUID id); ListenableFuture<InputStream> getInputStream(UUID id);  }
@Test public void getPort() { int localPort = 54321; when(options.localPort()).thenReturn(localPort); ServerSocketService service = new ServerSocketService(options); service.startAsync().awaitRunning(); int port = service.getPort(); service.stopAsync().awaitTerminated(); assertEquals(localPort, port); }