@Test
void testResize() {

    // Only enough space for 5 entries
    HpackContext ctx = new HpackContext(38 * 5);
    HttpField[] field = {
            new HttpField("fo0", "b0r"),
            new HttpField("fo1", "b1r"),
            new HttpField("fo2", "b2r"),
            new HttpField("fo3", "b3r"),
            new HttpField("fo4", "b4r"),
            new HttpField("fo5", "b5r"),
            new HttpField("fo6", "b6r"),
            new HttpField("fo7", "b7r"),
            new HttpField("fo8", "b8r"),
            new HttpField("fo9", "b9r"),
            new HttpField("foA", "bAr"),
    };
    Entry[] entry = new Entry[field.length];
    // Add 5 entries
    for (int i = 0; i <= 4; i++)
        entry[i] = ctx.add(field[i]);
    assertEquals(5, ctx.size());
    // check indexes
    int index = 66;
    for (int i = 0; i <= 4; i++) {
        assertEquals(index, ctx.index(entry[i]));
        assertEquals(entry[i], ctx.get(index));
        index--;
    }
    // resize so that only 2 entries may be held
    ctx.resize(38 * 2);
    assertEquals(2, ctx.size());
    // check indexes
    index = 63;
    for (int i = 3; i <= 4; i++) {
        assertEquals(index, ctx.index(entry[i]));
        assertEquals(entry[i], ctx.get(index));
        index--;
    }
    // resize so that 6.5 entries may be held
    ctx.resize(38 * 6 + 19);
    assertEquals(2, ctx.size());
    // check indexes
    index = 63;
    for (int i = 3; i <= 4; i++) {
        assertEquals(index, ctx.index(entry[i]));
        assertEquals(entry[i], ctx.get(index));
        index--;
    }
    // Add 5 entries
    for (int i = 5; i <= 9; i++)
        entry[i] = ctx.add(field[i]);
    assertEquals(6, ctx.size());
    // check indexes
    index = 67;
    for (int i = 4; i <= 9; i++) {
        assertEquals(index, ctx.index(entry[i]));
        assertEquals(entry[i], ctx.get(index));
        index--;
    }
    // resize so that only 100 entries may be held
    ctx.resize(38 * 100);
    assertEquals(6, ctx.size());
    // check indexes
    index = 67;
    for (int i = 4; i <= 9; i++) {
        assertEquals(index, ctx.index(entry[i]));
        assertEquals(entry[i], ctx.get(index));
        index--;
    }
    // add 50 fields
    for (int i = 0; i < 50; i++)
        ctx.add(new HttpField("n" + i, "v" + i));
    // check indexes
    index = 67 + 50;
    for (int i = 4; i <= 9; i++) {
        assertEquals(index, ctx.index(entry[i]));
        assertEquals(entry[i], ctx.get(index));
        index--;
    }
}