### Question:
CircularBuffer implements Iterable<T> { public ArrayList<T> addAll(ArrayList<T> elist, int uptoIndex) { if (uptoIndex > elist.size()) { log.error("uptoIndex is greater than elist size .. aborting addAll"); return elist; } for (int index=0; index < uptoIndex; index++) { T e = elist.get(index); if (e != null) { elist.set(index, add(e)); } } return elist; } CircularBuffer(int capacity); T add(T e); ArrayList<T> addAll(ArrayList<T> elist, int uptoIndex); @Override Iterator<T> iterator(); int size(); void clear();  }### Answer:
@Test public void testAddAll() { CircularBuffer<Elems> eb = new CircularBuffer<Elems>(2); Elems one = new Elems("String 1", false); eb.add(one); ArrayList<Elems> elist = new ArrayList<Elems>(); Elems two = new Elems("String 2", true); elist.add(two); Elems three = new Elems("String 3", true); elist.add(three); Elems four = new Elems("String 4", true); elist.add(four); ArrayList<Elems> retlist = eb.addAll(elist, 2); assertEquals(null, retlist.get(0)); assertEquals(true, retlist.get(1) == one); assertEquals(true, retlist.get(2) == four); ArrayList<Elems> retlist2 = eb.addAll(retlist, 3); assertEquals(null, retlist2.get(0)); assertEquals(true, retlist2.get(1) == two); assertEquals(true, retlist2.get(2) == three); ArrayList<Elems> retlist3 = eb.addAll(retlist2, 4); assertEquals(retlist3, retlist2); }