CollectionUtil { public static int enumerationSize(Enumeration<?> keys) { int n = 0; while (keys.hasMoreElements()) { keys.nextElement(); n++; } return n; } private  CollectionUtil(); static String key(Object key); static int enumerationSize(Enumeration<?> keys);  }
@SuppressWarnings("unchecked") @Test public void testEnumerationSize() { Enumeration<Object> enumeration = createMock(Enumeration.class); expect(enumeration.hasMoreElements()).andReturn(true); expect(enumeration.nextElement()).andReturn(1); expect(enumeration.hasMoreElements()).andReturn(true); expect(enumeration.nextElement()).andReturn(1); expect(enumeration.hasMoreElements()).andReturn(false); replay(enumeration); assertEquals(2, CollectionUtil.enumerationSize(enumeration)); verify(enumeration); }