### Question:
EachElement { public static <E> Generator<E> from(Iterable<? extends E> iterable) { return iterable == null ? null : EachElement.from(iterable.iterator()); } private  EachElement(); static Generator<E> from(Iterable<? extends E> iterable); @SuppressWarnings("unchecked") static Generator<Map.Entry<K, V>> from(Map<? extends K, ? extends V> map); static Generator<E> from(E... array); static Generator<E> from(Iterator<? extends E> iter);  }### Answer:
@Test public void testFromNull() { assertNull(EachElement.from((Collection<?>) null)); assertNull(EachElement.from((Map<?, ?>) null)); assertNull(EachElement.from((Iterator<?>) null)); assertNull(EachElement.from((Object[]) null)); }
@Test public void testWithList() { Collection<?> col = EachElement.from(list).toCollection(); assertEquals("[0, 1, 2, 3, 4]", col.toString()); }
@Test @SuppressWarnings("unchecked") public void testWithMap() { List<?> col = (List<?>) EachElement.from(map).toCollection(); int i = 0; for (;i<col.size();i++) { Map.Entry<String, String> entry = (Map.Entry<String, String>) col.get(i); if (entry.getKey().equals("1")) { assertEquals("1-1", entry.getValue()); } else if (entry.getKey().equals("2")) { assertEquals("2-1", entry.getValue()); } else if (entry.getKey().equals("3")) { assertEquals("3-1", entry.getValue()); } else if (entry.getKey().equals("4")) { assertEquals("4-1", entry.getValue()); } else if (entry.getKey().equals("5")) { assertEquals("5-1", entry.getValue()); } } assertEquals(5, i); }
@Test public void testWithArray() { Collection<?> col = EachElement.from(array).toCollection(); assertEquals("[1, 2, 3, 4, 5]", col.toString()); }
@Test public void testWithStop() { assertEquals("[0, 1, 2]", new UntilGenerate<Integer>(new Offset(3), EachElement.from(list)).toCollection().toString()); assertEquals("[0, 1, 2, 3]", new GenerateUntil<Integer>(EachElement.from(list), new Offset(3)).toCollection().toString()); assertEquals("[0, 1, 2]", new WhileGenerate<Integer>(new Limit(3), EachElement.from(list)).toCollection().toString()); assertEquals("[0, 1, 2, 3]", new GenerateWhile<Integer>(EachElement.from(list), new Limit(3)).toCollection().toString()); }
@Test public void testWithIterator() { Collection<?> col = EachElement.from(list.iterator()).toCollection(); assertEquals("[0, 1, 2, 3, 4]", col.toString()); }