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

autofixture.generators.vavr.VavrMapGenerator Maven / Gradle / Ivy

package autofixture.generators.vavr;

import autofixture.interfaces.FixtureContract;
import autofixture.interfaces.InstanceGenerator;
import autofixture.interfaces.InstanceType;
import com.google.common.base.Supplier;

import java.util.Map;
import java.util.function.Function;

public class VavrMapGenerator implements InstanceGenerator {

  private Function mapFactory;
  private Class clazz;
  private Supplier emptySupplier;

  public VavrMapGenerator(Class clazz,
                          Function multimapFactory,
                          final Supplier emptySupplier) {
    mapFactory = multimapFactory;
    this.clazz = clazz;
    this.emptySupplier = emptySupplier;
  }

  @Override
  public  boolean appliesTo(final InstanceType instanceType) {
    return instanceType.isRawTypeAssignableFrom(clazz);
  }

  @Override
  public  T next(final InstanceType instanceType, final FixtureContract fixture) {
    Map map = instanceType.turnIntoMapInstance(fixture);
    return (T) mapFactory.apply(map);
  }

  @Override
  public  T nextEmpty(final InstanceType instanceType, final FixtureContract fixture) {
    return (T)emptySupplier.get();
  }

  @Override
  public void setOmittingAutoProperties(final boolean isOn) {

  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy