autofixture.generators.vavr.VavrIteratorGenerator Maven / Gradle / Ivy
The newest version!
package autofixture.generators.vavr;
import autofixture.interfaces.FixtureContract;
import autofixture.interfaces.InstanceGenerator;
import autofixture.interfaces.InstanceType;
import io.vavr.collection.Iterator;
import io.vavr.collection.List;
public class VavrIteratorGenerator implements InstanceGenerator {
//apparently, when the lists are not cached,
//the size of the iterator becomes 0 pretty soon
private List iteratorParents = List.empty();
@Override
public boolean appliesTo(final InstanceType instanceType) {
return instanceType.isRawTypeAssignableFrom(io.vavr.collection.Iterator.class);
}
@Override
public T next(final InstanceType instanceType, final FixtureContract fixture) {
List> parent = List.ofAll(instanceType.turnIntoCollection(fixture));
iteratorParents = iteratorParents.append(parent);
Iterator> iterator = parent.iterator();
return (T) iterator;
}
@Override
public T nextEmpty(final InstanceType instanceType, final FixtureContract fixture) {
return (T)Iterator.empty();
}
@Override
public void setOmittingAutoProperties(final boolean isOn) {
}
}