net.jqwik.engine.providers.NullableArbitraryProvider Maven / Gradle / Ivy
package net.jqwik.engine.providers;
import java.util.*;
import java.util.stream.*;
import net.jqwik.api.*;
import net.jqwik.api.constraints.*;
import net.jqwik.api.providers.*;
public class NullableArbitraryProvider implements ArbitraryProvider {
@Override
public boolean canProvideFor(TypeUsage targetType) {
return targetType.isNullable() && !targetType.isAnnotated(WithNull.class);
}
@Override
public Set> provideFor(
TypeUsage targetType,
SubtypeProvider subtypeProvider
) {
TypeUsage nonNullType = targetType.asNotNullable();
Set> rawArbitraries = subtypeProvider.apply(nonNullType);
return rawArbitraries.stream()
.map(a -> a.injectNull(0.05))
.collect(Collectors.toSet());
}
@Override
public int priority() {
// Replace most providers if type is nullable
return 101;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy