slowCheck: expect flatMap argument function to always return non-null

This commit is contained in:
peter
2017-07-13 15:26:22 +02:00
parent dae7dcdcd5
commit e057bdaf59

View File

@@ -39,7 +39,12 @@ public final class Generator<T> {
}
public <V> Generator<V> flatMap(@NotNull Function<T,Generator<V>> fun) {
return from(data -> fun.apply(generateValue(data)).generateValue(data));
return from(data -> {
T value = generateValue(data);
Generator<V> result = fun.apply(value);
if (result == null) throw new NullPointerException(fun + " returned null on " + value);
return result.generateValue(data);
});
}
public Generator<T> noShrink() {