AbstractServerStream extends AbstractStream<IdT> implements ServerStream { @Override public final void writeHeaders(Metadata headers) { Preconditions.checkNotNull(headers, "headers"); outboundPhase(Phase.HEADERS); headersSent = true; internalSendHeaders(headers); outboundPhase(Phase.MESSAGE); } protected  AbstractServerStream(WritableBufferAllocator bufferAllocator,
                                 int maxMessageSize); final void setListener(ServerStreamListener listener); @Override final void writeHeaders(Metadata headers); @Override final void writeMessage(InputStream message); @Override final void close(Status status, Metadata trailers); void inboundDataReceived(ReadableBuffer frame, boolean endOfStream); void complete(); final void abortStream(Status status, boolean notifyClient); @Override boolean isClosed(); @Override Attributes attributes();  }
@Test public void writeHeaders_failsOnNullHeaders() { AbstractServerStreamBase stream = new AbstractServerStreamBase(allocator, MAX_MESSAGE_SIZE); thrown.expect(NullPointerException.class); stream.writeHeaders(null); }
@Test public void writeHeaders_failsIfAlreadySent() { defaultStream.writeHeaders(new Metadata()); thrown.expect(IllegalStateException.class); defaultStream.writeHeaders(new Metadata()); }
@Test public void writeHeaders() { final AtomicReference<Metadata> capturedHeaders = new AtomicReference<Metadata>(null); Metadata headers = new Metadata(); AbstractServerStreamBase stream = new AbstractServerStreamBase(allocator, MAX_MESSAGE_SIZE) { @Override protected void internalSendHeaders(Metadata captured) { capturedHeaders.set(captured); } }; stream.writeHeaders(headers); assertEquals(headers, capturedHeaders.get()); assertEquals(Phase.MESSAGE, stream.outboundPhase()); }