@Test
public void serverShouldSend431OnHeaderSizeErrorWhenDecodingInitialHeaders() 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(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(PROTOCOL_ERROR.code()), eq(promise))).thenReturn(future);
    handler.exceptionCaught(ctx, e);
    ArgumentCaptor<Http2Headers> captor = ArgumentCaptor.forClass(Http2Headers.class);
    verify(encoder).writeHeaders(eq(ctx), eq(STREAM_ID),
            captor.capture(), eq(padding), eq(true), eq(promise));
    Http2Headers headers = captor.getValue();
    assertEquals(HttpResponseStatus.REQUEST_HEADER_FIELDS_TOO_LARGE.codeAsText(), headers.status());
    verify(frameWriter).writeRstStream(ctx, STREAM_ID, PROTOCOL_ERROR.code(), promise);
}