### Question:
CollectionHelper { public static <T> Collection<T> getCollectionOf( final Class<T> clazz, final Collection<?> collection ) { return getCollectionOf(clazz, collection, new ArrayList<>()); } private  CollectionHelper(); static Collection<T> getCollectionOf(
            final Class<T> clazz,
            final Collection<?> collection
    ); static ArrayList<T> getArrayListOf(
            final Class<T> clazz,
            final Collection<?> collection
    ); static HashSet<T> getHashSetOf(
            final Class<T> clazz,
            final Collection<?> collection
    ); static U getCollectionOf(
            final Class<T> clazz,
            final Collection<?> collection,
            final U resultCollection
    );  }### Answer:
@Test public void testGetCollectionEmpty() { Collection<String> casted = CollectionHelper.getCollectionOf( String.class, Collections.EMPTY_LIST ); Assert.assertEquals(casted, Collections.EMPTY_LIST); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testHomogenousCollection() { Collection<Object> notAllStrings = Arrays.asList("one", "two", new HashMap<>()); CollectionHelper.getCollectionOf(String.class, notAllStrings); }
@Test public void testGetCollectionCustom() { TreeSet<String> casted = CollectionHelper.getCollectionOf( String.class, OBJ_COLLECTION_OF_STRINGS, new TreeSet<>() ); Assert.assertEquals(casted.size(), EXPECTED_SIZE); Assert.assertEquals(casted.getClass(), TreeSet.class); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testGetCollectionCustomOnNonemptyResultCollection() { CollectionHelper.getCollectionOf( String.class, OBJ_COLLECTION_OF_STRINGS, Collections.singletonList("test") ); }