org.unitils.objectvalidation.objectcreator.ObjectCreatorMockedFieldsImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unitils-objectvalidation Show documentation
Show all versions of unitils-objectvalidation Show documentation
Unitils module to validate objects.
package org.unitils.objectvalidation.objectcreator;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.easymock.classextension.internal.objenesis.ObjenesisStd;
import org.unitils.objectvalidation.ObjectCreator;
import org.unitils.objectvalidation.objectcreator.generator.Generator;
import org.unitils.objectvalidation.objectcreator.generator.helper.GeneratorHelper;
import org.unitils.objectvalidation.utils.ObjectCreatorTypeWrapper;
import org.unitils.objectvalidation.utils.TreeNode;
import org.unitils.util.ReflectionUtils;
/**
* @author Matthieu Mestrez, Willemijn Wouters
* @since 07/04/14.
*/
public class ObjectCreatorMockedFieldsImpl extends BaseObjectCreator implements ObjectCreator {
private static final Log LOGGER = LogFactory.getLog(ObjectCreatorMockedFieldsImpl.class);
private int instances = 0;
public ObjectCreatorMockedFieldsImpl() {
super();
}
/**
* @param generators
*/
public ObjectCreatorMockedFieldsImpl(Generator... generators) {
super(generators);
}
@Override
public Object createRandomObject(Type type) {
Object randomObject = null;
ObjectCreatorTypeWrapper typeWrapper = new ObjectCreatorTypeWrapper(type);
if (typeWrapper.isPrimitive() || typeWrapper.isString() || typeWrapper.getWrappedType().getClass().isEnum()) {
try {
return getGenerator().generateObject(typeWrapper.getClassOfType(), new ArrayList