### Question:
ReflectionHelper { public static <T> T[] newArrayFromCollection(final Collection<?> collection, final Class<T> elementType) { if (collection == null) { return null; } @SuppressWarnings({"unchecked"}) T[] array = (T[]) Array.newInstance(elementType, collection.size()); int i = 0; for (Object element : collection) { Array.set(array, i++, element); } return array; } private  ReflectionHelper(); static Class<?> getClassForName(final String className); static Class<?> getArrayType(final Class<?> type); static Field getDeclaredField(final Object bean, final String fieldName); static Object getFieldValue(final Object bean, final String fieldName); static Class<?> getGenericType(final Field field); static T newCollectionInstance(final Class<T> clazz); static T newInstance(final Class<T> clazz); static T newInstance(final String fullyQualifiedClassName, final Class<T> superType); static List<T> createInstances(final List<String> fullyQualifiedClassNames, final Class<T> superType); static void setFieldValue(final Object bean, final String fieldName, final Object value); static Set<Field> getDeclaredFieldsWithAnnotationRecursively(final Class<?> clazz,
                                                                        final Class<? extends Annotation> annotationClass); static T[] newArrayFromCollection(final Collection<?> collection, final Class<T> elementType);  }### Answer:
@Test @SuppressWarnings("ConstantConditions") public void newArrayFromCollectionReturnsNullWhenCollectionIsNull() { Object[] objects = ReflectionHelper.newArrayFromCollection(null, Integer.class); assertThat(objects).isNull(); }
@Test public void newArrayFromCollectionReturnsArrayOfSizeZeroWhenCollectionIsEmpty() { Object[] objects = ReflectionHelper.newArrayFromCollection(emptySet(), Integer.class); assertThat(objects).hasSize(0); }
@Test public void newArrayFromCollectionReturnsArrayOfSizeTwoWhenCollectionHasTwoElements() { List<Integer> list = asList(1, 2); Integer[] objects = ReflectionHelper.newArrayFromCollection(list, Integer.class); assertThat(objects).containsOnly(1, 2); }