### Question:
ServerCallImpl extends ServerCall<ReqT, RespT> { @Override public void sendMessage(RespT message) { checkState(sendHeadersCalled, "sendHeaders has not been called"); checkState(!closeCalled, "call is closed"); if (method.getType().serverSendsOneMessage() && messageSent) { internalClose(Status.INTERNAL.withDescription(TOO_MANY_RESPONSES)); return; } messageSent = true; try { InputStream resp = method.streamResponse(message); stream.writeMessage(resp); stream.flush(); } catch (RuntimeException e) { close(Status.fromThrowable(e), new Metadata()); } catch (Error e) { close( Status.CANCELLED.withDescription("Server sendMessage() failed with Error"), new Metadata()); throw e; } } ServerCallImpl(ServerStream stream, MethodDescriptor<ReqT, RespT> method,
      Metadata inboundHeaders, Context.CancellableContext context,
      DecompressorRegistry decompressorRegistry, CompressorRegistry compressorRegistry,
      CallTracer serverCallTracer); @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 getAttributes(); @Override String getAuthority(); @Override MethodDescriptor<ReqT, RespT> getMethodDescriptor();  }### Answer:
@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); }