Counters implements Iterable<CounterGroup> { @Override public Iterator<CounterGroup> iterator() { return groups.values().iterator(); } Counters(); Counters addCounterGroup(CounterGroup group); CounterGroup getCounterGroup(String name); @Override Iterator<CounterGroup> iterator(); boolean isEmpty();  }
@Test public void testIterator() { Counters counters = new Counters(); CounterGroup cg1 = new CounterGroup("sqoop1"); CounterGroup cg2 = new CounterGroup("sqoop2"); counters.addCounterGroup(cg1); counters.addCounterGroup(cg2); int count = 0; for (CounterGroup cg : counters) { count++; } Assert.assertEquals(2, count); }