autofixture.publicinterface.inline.GenerationConstrainedByValueRejection Maven / Gradle / Ivy
The newest version!
package autofixture.publicinterface.inline;
import autofixture.interfaces.FixtureContract;
import autofixture.interfaces.InlineConstrainedGenerator;
import autofixture.publicinterface.constraints.GenerationConstraint;
import com.google.common.reflect.TypeToken;
public class GenerationConstrainedByValueRejection implements InlineConstrainedGenerator {
private final GenerationConstraint constraint;
public GenerationConstrainedByValueRejection(final GenerationConstraint constraint) {
this.constraint = constraint;
}
@Override
public T next(final TypeToken typeToken, final FixtureContract fixture) {
T currentValue;
do {
currentValue = fixture.create(typeToken);
} while (constraint.doesNotAccept(currentValue));
return currentValue;
}
}