### Question:
IntegerAggregator implements Aggregator { public DbIterator iterator() { List<Tuple> result=new ArrayList<>(); groupValue.forEach((k,v)->{ Tuple tuple; if(groupByField==Aggregator.NO_GROUPING){ List<Type> temp=new ArrayList<>(); temp.add(groupByFieldType); tuple=new Tuple(new TupleDesc(temp.toArray(new Type[0]))); tuple.setField(0,new IntField(v)); }else{ List<Type> temp=new ArrayList<>(); temp.add(groupByFieldType); temp.add(Type.INT_TYPE); tuple=new Tuple(new TupleDesc(temp.toArray(new Type[0]))); tuple.setField(0,k); tuple.setField(1,new IntField(v)); } result.add(tuple); }); if(result.size()==0){ return new TupleIterator(new TupleDesc(new Type[]{groupByFieldType}),result); } return new TupleIterator(result.get(0).getTupleDesc(),result); } IntegerAggregator(int gbfield, Type gbfieldtype, int afield, Op what); void mergeTupleIntoGroup(Tuple tup); DbIterator iterator();  }### Answer:
@Test public void testIterator() throws Exception { scan1.open(); IntegerAggregator agg = new IntegerAggregator(0, Type.INT_TYPE, 1, Aggregator.Op.SUM); try { while (true) agg.mergeTupleIntoGroup(scan1.next()); } catch (NoSuchElementException e) { } DbIterator it = agg.iterator(); it.open(); int count = 0; try { while (true) { it.next(); count++; } } catch (NoSuchElementException e) { } assertEquals(3, count); it.rewind(); count = 0; try { while (true) { it.next(); count++; } } catch (NoSuchElementException e) { } assertEquals(3, count); it.close(); try { it.next(); throw new Exception("IntegerAggregator iterator yielded tuple after close"); } catch (Exception e) { } }