@Test void rawInterfaceCollectionTypesMustBeReturnedEmpty() throws Exception { when(context.getParameters()).thenReturn(parameters); Field field = Foo.class.getDeclaredField("rawInterfaceList"); Collection<?> collection = collectionPopulator.getRandomCollection(field, context); assertThat(collection).isEmpty(); }
@SuppressWarnings({"unchecked", "rawtypes"}) Collection<?> getRandomCollection(final Field field, final RandomizationContext context) { int randomSize = getRandomCollectionSize(context.getParameters()); Class<?> fieldType = field.getType(); Type fieldGenericType = field.getGenericType(); Collection collection; if (isInterface(fieldType)) { collection = getEmptyImplementationForCollectionInterface(fieldType); } else { collection = createEmptyCollectionForType(fieldType, randomSize); } if (isParameterizedType(fieldGenericType)) { ParameterizedType parameterizedType = (ParameterizedType) fieldGenericType; Type type = parameterizedType.getActualTypeArguments()[0]; if (isPopulatable(type)) { for (int i = 0; i < randomSize; i++) { Object item = easyRandom.doPopulateBean((Class<?>) type, context); collection.add(item); } } } return collection; }
CollectionPopulator { @SuppressWarnings({"unchecked", "rawtypes"}) Collection<?> getRandomCollection(final Field field, final RandomizationContext context) { int randomSize = getRandomCollectionSize(context.getParameters()); Class<?> fieldType = field.getType(); Type fieldGenericType = field.getGenericType(); Collection collection; if (isInterface(fieldType)) { collection = getEmptyImplementationForCollectionInterface(fieldType); } else { collection = createEmptyCollectionForType(fieldType, randomSize); } if (isParameterizedType(fieldGenericType)) { ParameterizedType parameterizedType = (ParameterizedType) fieldGenericType; Type type = parameterizedType.getActualTypeArguments()[0]; if (isPopulatable(type)) { for (int i = 0; i < randomSize; i++) { Object item = easyRandom.doPopulateBean((Class<?>) type, context); collection.add(item); } } } return collection; } }
CollectionPopulator { @SuppressWarnings({"unchecked", "rawtypes"}) Collection<?> getRandomCollection(final Field field, final RandomizationContext context) { int randomSize = getRandomCollectionSize(context.getParameters()); Class<?> fieldType = field.getType(); Type fieldGenericType = field.getGenericType(); Collection collection; if (isInterface(fieldType)) { collection = getEmptyImplementationForCollectionInterface(fieldType); } else { collection = createEmptyCollectionForType(fieldType, randomSize); } if (isParameterizedType(fieldGenericType)) { ParameterizedType parameterizedType = (ParameterizedType) fieldGenericType; Type type = parameterizedType.getActualTypeArguments()[0]; if (isPopulatable(type)) { for (int i = 0; i < randomSize; i++) { Object item = easyRandom.doPopulateBean((Class<?>) type, context); collection.add(item); } } } return collection; } CollectionPopulator(final EasyRandom easyRandom); }
CollectionPopulator { @SuppressWarnings({"unchecked", "rawtypes"}) Collection<?> getRandomCollection(final Field field, final RandomizationContext context) { int randomSize = getRandomCollectionSize(context.getParameters()); Class<?> fieldType = field.getType(); Type fieldGenericType = field.getGenericType(); Collection collection; if (isInterface(fieldType)) { collection = getEmptyImplementationForCollectionInterface(fieldType); } else { collection = createEmptyCollectionForType(fieldType, randomSize); } if (isParameterizedType(fieldGenericType)) { ParameterizedType parameterizedType = (ParameterizedType) fieldGenericType; Type type = parameterizedType.getActualTypeArguments()[0]; if (isPopulatable(type)) { for (int i = 0; i < randomSize; i++) { Object item = easyRandom.doPopulateBean((Class<?>) type, context); collection.add(item); } } } return collection; } CollectionPopulator(final EasyRandom easyRandom);  }
CollectionPopulator { @SuppressWarnings({"unchecked", "rawtypes"}) Collection<?> getRandomCollection(final Field field, final RandomizationContext context) { int randomSize = getRandomCollectionSize(context.getParameters()); Class<?> fieldType = field.getType(); Type fieldGenericType = field.getGenericType(); Collection collection; if (isInterface(fieldType)) { collection = getEmptyImplementationForCollectionInterface(fieldType); } else { collection = createEmptyCollectionForType(fieldType, randomSize); } if (isParameterizedType(fieldGenericType)) { ParameterizedType parameterizedType = (ParameterizedType) fieldGenericType; Type type = parameterizedType.getActualTypeArguments()[0]; if (isPopulatable(type)) { for (int i = 0; i < randomSize; i++) { Object item = easyRandom.doPopulateBean((Class<?>) type, context); collection.add(item); } } } return collection; } CollectionPopulator(final EasyRandom easyRandom);   }