@Test
public void serverShouldCreateStreamIfNeededBeforeSending431() throws Exception {

    int padding = 0;
    handler = newHandler();
    Http2Exception e = new Http2Exception.HeaderListSizeException(STREAM_ID, PROTOCOL_ERROR,
        "Header size exceeded max allowed size 8196", true);
    when(connection.stream(STREAM_ID)).thenReturn(null);
    when(remote.createStream(STREAM_ID, true)).thenReturn(stream);
    when(stream.id()).thenReturn(STREAM_ID);
    when(connection.isServer()).thenReturn(true);
    when(stream.isHeadersSent()).thenReturn(false);
    when(remote.lastStreamCreated()).thenReturn(STREAM_ID);
    when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID),
        eq(Http2Error.PROTOCOL_ERROR.code()), eq(promise))).thenReturn(future);
    handler.exceptionCaught(ctx, e);
    verify(remote).createStream(STREAM_ID, true);
    verify(encoder).writeHeaders(eq(ctx), eq(STREAM_ID),
        any(Http2Headers.class), eq(padding), eq(true), eq(promise));
    verify(frameWriter).writeRstStream(ctx, STREAM_ID, PROTOCOL_ERROR.code(), promise);
}