ServerCallImpl extends ServerCall<RespT> { @Override public void sendMessage(RespT message) { checkState(sendHeadersCalled, "sendHeaders has not been called"); checkState(!closeCalled, "call is closed"); try { InputStream resp = method.streamResponse(message); stream.writeMessage(resp); stream.flush(); } catch (RuntimeException e) { close(Status.fromThrowable(e), new Metadata()); throw e; } catch (Throwable t) { close(Status.fromThrowable(t), new Metadata()); throw new RuntimeException(t); } } ServerCallImpl(ServerStream stream, MethodDescriptor<ReqT, RespT> method,
      Metadata inboundHeaders, Context.CancellableContext context,
      DecompressorRegistry decompressorRegistry, CompressorRegistry compressorRegistry); @Override void request(int numMessages); @Override void sendHeaders(Metadata headers); @Override void sendMessage(RespT message); @Override void setMessageCompression(boolean enable); @Override void setCompression(String compressorName); @Override boolean isReady(); @Override void close(Status status, Metadata trailers); @Override boolean isCancelled(); @Override Attributes attributes();  }
@Test public void sendMessage() { call.sendHeaders(new Metadata()); call.sendMessage(1234L); verify(stream).writeMessage(isA(InputStream.class)); verify(stream).flush(); }
@Test public void sendMessage_failsIfheadersUnsent() { thrown.expect(IllegalStateException.class); thrown.expectMessage("sendHeaders has not been called"); call.sendMessage(1234L); }