autofixture.generators.vavr.VavrCollectionGenerator 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.Collection;
import java.util.function.Function;
public class VavrCollectionGenerator implements InstanceGenerator {
private Class clazz;
private Function, TCollection> collectionFactory;
private Supplier emptyFactory;
public VavrCollectionGenerator(
Class clazz,
Function, TCollection> factory,
Supplier emptyFactory) {
this.clazz = clazz;
collectionFactory = factory;
this.emptyFactory = emptyFactory;
}
@Override
public boolean appliesTo(final InstanceType instanceType) {
return instanceType.isRawTypeAssignableFrom(clazz);
}
@Override
public T next(final InstanceType instanceType, final FixtureContract fixture) {
Collection> elements = instanceType.turnIntoCollection(fixture);
return (T) collectionFactory.apply(elements);
}
@Override
public T nextEmpty(final InstanceType instanceType, final FixtureContract fixture) {
return (T) emptyFactory.get();
}
@Override
public void setOmittingAutoProperties(final boolean isOn) {
}
}