### Question:
ServerCallImpl extends ServerCall<ReqT, RespT> { @Override public void sendHeaders(Metadata headers) { checkState(!sendHeadersCalled, "sendHeaders has already been called"); checkState(!closeCalled, "call is closed"); headers.discardAll(MESSAGE_ENCODING_KEY); if (compressor == null) { compressor = Codec.Identity.NONE; } else { if (messageAcceptEncoding != null) { if (!GrpcUtil.iterableContains( ACCEPT_ENCODING_SPLITTER.split(new String(messageAcceptEncoding, GrpcUtil.US_ASCII)), compressor.getMessageEncoding())) { compressor = Codec.Identity.NONE; } } else { compressor = Codec.Identity.NONE; } } headers.put(MESSAGE_ENCODING_KEY, compressor.getMessageEncoding()); stream.setCompressor(compressor); headers.discardAll(MESSAGE_ACCEPT_ENCODING_KEY); byte[] advertisedEncodings = InternalDecompressorRegistry.getRawAdvertisedMessageEncodings(decompressorRegistry); if (advertisedEncodings.length != 0) { headers.put(MESSAGE_ACCEPT_ENCODING_KEY, advertisedEncodings); } sendHeadersCalled = true; stream.writeHeaders(headers); } 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 sendHeader_firstCall() { Metadata headers = new Metadata(); call.sendHeaders(headers); verify(stream).writeHeaders(headers); }
@Test public void sendHeader_failsOnSecondCall() { call.sendHeaders(new Metadata()); thrown.expect(IllegalStateException.class); thrown.expectMessage("sendHeaders has already been called"); call.sendHeaders(new Metadata()); }