All Downloads are FREE. Search and download functionalities are using the official Maven repository.

autofixture.generators.objects.implementationdetails.ReflectionInstanceField Maven / Gradle / Ivy

package autofixture.generators.objects.implementationdetails;

import autofixture.interfaces.FixtureContract;
import autofixture.interfaces.InstanceField;
import autofixture.interfaces.InstanceType;
import com.google.common.reflect.TypeToken;

import java.lang.reflect.Field;

public class ReflectionInstanceField implements InstanceField {

  private final Field field;
  private final InstanceType instanceType;
  private final T instance;

  public ReflectionInstanceField(final Field field, final InstanceType instanceType, final T instance) {
    this.field = field;
    this.instanceType = instanceType;
    this.instance = instance;
  }

  @Override
  public TypeToken resolveActualType() {
    return instanceType.resolveActualTypeOf(field);
  }

  @Override
  public void setValueUsing(final FixtureContract fixture) throws IllegalAccessException {
    field.set(instance, fixture.create(resolveActualType()));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy