ServerImpl extends io.grpc.Server { @Override public int getPort() { synchronized (lock) { checkState(started, "Not started"); checkState(!terminated, "Already terminated"); return transportServer.getPort(); } } ServerImpl(Executor executor, InternalHandlerRegistry registry, HandlerRegistry fallbackRegistry,
      InternalServer transportServer, Context rootContext,
      DecompressorRegistry decompressorRegistry, CompressorRegistry compressorRegistry); @Override ServerImpl start(); @Override int getPort(); @Override ServerImpl shutdown(); @Override ServerImpl shutdownNow(); @Override boolean isShutdown(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override void awaitTermination(); @Override boolean isTerminated();  }
@Test public void getPort() throws Exception { transportServer = new SimpleServer() { @Override public int getPort() { return 65535; } }; ServerImpl server = new ServerImpl(executor, registry, fallbackRegistry, transportServer, SERVER_CONTEXT, decompressorRegistry, compressorRegistry); server.start(); Truth.assertThat(server.getPort()).isEqualTo(65535); }
@Test public void getPortBeforeStartedFails() { transportServer = new SimpleServer(); ServerImpl server = new ServerImpl(executor, registry, fallbackRegistry, transportServer, SERVER_CONTEXT, decompressorRegistry, compressorRegistry); thrown.expect(IllegalStateException.class); thrown.expectMessage("started"); server.getPort(); }