@Test
public void testSubList() {

    CategorizedCircularBuffer<String, Long> ccb = new CategorizedCircularBuffer<String, Long>(4);
    ccb.add(0L, "e0"); // 3
    ccb.add(1L, "e2"); // 2
    ccb.add(1L, "e3"); // 1
    ccb.add(3L, "e4"); // idx 0
    {
        List<String> l = ccb.subList(2, 4);
        assertEquals(2, l.size());
        assertEquals("e2", l.get(0));
        assertEquals("e0", l.get(1));
        List<String> kl = ccb.subListByKey(1L, 0, 2);
        assertEquals(2, kl.size());
        assertEquals("e3", kl.get(0));
        assertEquals("e2", kl.get(1));
    }
    ccb.add(3L, "e5"); // idx 0; other will scroll up
    {
        List<String> l = ccb.subList(2, 4);
        assertEquals(2, l.size());
        assertEquals("e3", l.get(0));
        assertEquals("e2", l.get(1));
    }
    ccb.add(3L, "e6"); // idx 0; other will scroll up
    {
        List<String> kl = ccb.subListByKey(1L, 0, 1);
        assertEquals(1, kl.size());
        assertEquals("e3", kl.get(0));
    }
}