@Test
public void writeRstOnClosedStreamShouldSucceed() throws Exception {

    handler = newHandler();
    when(stream.id()).thenReturn(STREAM_ID);
    when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID),
            anyLong(), any(ChannelPromise.class))).thenReturn(future);
    when(stream.state()).thenReturn(CLOSED);
    when(stream.isHeadersSent()).thenReturn(true);
    // The stream is "closed" but is still known about by the connection (connection().stream(..)
    // will return the stream). We should still write a RST_STREAM frame in this scenario.
    handler.resetStream(ctx, STREAM_ID, STREAM_CLOSED.code(), promise);
    verify(frameWriter).writeRstStream(eq(ctx), eq(STREAM_ID), anyLong(), any(ChannelPromise.class));
}