From 36c788701f98c60fbea417198dbbb3407fa599bc Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Thu, 6 Jun 2024 20:26:14 +0300 Subject: [PATCH] WIP: fixup nullability annotations and generic variance --- .../main/java/net/jqwik/api/Arbitraries.java | 78 +++++++++---------- .../main/java/net/jqwik/api/Arbitrary.java | 4 +- api/src/main/java/net/jqwik/api/Builders.java | 8 +- .../main/java/net/jqwik/api/Combinators.java | 78 +++++++++---------- .../java/net/jqwik/api/RandomGenerator.java | 3 +- .../main/java/net/jqwik/api/Shrinkable.java | 2 +- api/src/main/java/net/jqwik/api/Tuple.java | 34 ++++---- .../jqwik/api/arbitraries/ArrayArbitrary.java | 6 +- .../api/arbitraries/FunctionArbitrary.java | 4 +- .../api/arbitraries/IteratorArbitrary.java | 6 +- .../jqwik/api/arbitraries/ListArbitrary.java | 6 +- .../jqwik/api/arbitraries/MapArbitrary.java | 4 +- .../jqwik/api/arbitraries/SetArbitrary.java | 6 +- .../api/arbitraries/SizableArbitrary.java | 4 +- .../api/arbitraries/StreamArbitrary.java | 6 +- .../api/arbitraries/StreamableArbitrary.java | 4 +- .../api/arbitraries/TraverseArbitrary.java | 4 +- .../jqwik/api/arbitraries/TypeArbitrary.java | 4 +- .../api/statistics/StatisticsCoverage.java | 2 +- .../customized-parameter-generation.md | 10 +-- .../StatisticsCoverageExamples.java | 5 +- .../engine/facades/ArbitrariesFacadeImpl.java | 28 +++---- .../engine/facades/CombinatorsFacadeImpl.java | 2 +- .../statistics/StatisticsCollectorImpl.java | 6 +- .../arbitraries/DefaultArrayArbitrary.java | 2 +- .../arbitraries/DefaultFunctionArbitrary.java | 14 ++-- .../arbitraries/DefaultIteratorArbitrary.java | 2 +- .../arbitraries/DefaultListArbitrary.java | 8 +- .../arbitraries/DefaultSetArbitrary.java | 2 +- .../arbitraries/DefaultStreamArbitrary.java | 2 +- .../arbitraries/EdgeCasesSupport.java | 2 +- .../arbitraries/FrequencyOfArbitrary.java | 4 +- .../FromGeneratorWithSizeArbitrary.java | 4 +- .../properties/arbitraries/LazyArbitrary.java | 4 +- .../arbitraries/LazyOfArbitrary.java | 6 +- .../arbitraries/OneOfArbitrary.java | 5 +- .../arbitraries/RecursiveArbitrary.java | 6 +- .../combinations/DefaultListCombinator.java | 2 +- .../exhaustive/ExhaustiveGenerators.java | 2 +- .../FlatMappedExhaustiveGenerator.java | 6 +- .../randomized/AbstractFunctionGenerator.java | 6 +- .../randomized/ConstantFunctionGenerator.java | 2 +- .../randomized/FrequencyGenerator.java | 2 +- .../randomized/FunctionGenerator.java | 2 +- .../randomized/RandomGenerators.java | 4 +- .../shrinking/ChooseValueShrinkable.java | 4 +- .../support/ChooseRandomlyByFrequency.java | 6 +- .../statistics/StatisticsCoverageTests.java | 8 +- kotlin/build.gradle | 1 + .../jqwik/kotlin/api/BuildersExtensions.kt | 6 +- .../net/jqwik/kotlin/api/SequenceArbitrary.kt | 4 +- .../kotlin/api/SizableArbitraryExtensions.kt | 2 +- .../jqwik/kotlin/CollectionExtensionsTests.kt | 4 +- .../net/jqwik/kotlin/InternalModifierTests.kt | 6 +- 54 files changed, 231 insertions(+), 211 deletions(-) diff --git a/api/src/main/java/net/jqwik/api/Arbitraries.java b/api/src/main/java/net/jqwik/api/Arbitraries.java index b46c0943c..cefb5d81a 100644 --- a/api/src/main/java/net/jqwik/api/Arbitraries.java +++ b/api/src/main/java/net/jqwik/api/Arbitraries.java @@ -25,13 +25,13 @@ public static abstract class ArbitrariesFacade { implementation = FacadeLoader.load(ArbitrariesFacade.class); } - public abstract Arbitrary oneOf(Collection> all); + public abstract Arbitrary oneOf(Collection> all); public abstract ActionSequenceArbitrary sequences(Arbitrary> actionArbitrary); - public abstract Arbitrary frequencyOf(List>> frequencies); + public abstract Arbitrary frequencyOf(List>> frequencies); - public abstract <@Nullable T> Arbitrary just(@Nullable T value); + public abstract Arbitrary just(T value); public abstract IntegerArbitrary integers(); @@ -57,36 +57,36 @@ public static abstract class ArbitrariesFacade { public abstract Arbitrary defaultFor(TypeUsage typeUsage, Function> noDefaultResolver); - public abstract Arbitrary lazy(Supplier> arbitrarySupplier); + public abstract Arbitrary lazy(Supplier> arbitrarySupplier); public abstract TypeArbitrary forType(Class targetType); - public abstract MapArbitrary maps(Arbitrary keysArbitrary, Arbitrary valuesArbitrary); + public abstract MapArbitrary maps(Arbitrary keysArbitrary, Arbitrary valuesArbitrary); - public abstract Arbitrary> entries(Arbitrary keysArbitrary, Arbitrary valuesArbitrary); + public abstract Arbitrary> entries(Arbitrary keysArbitrary, Arbitrary valuesArbitrary); - public abstract Arbitrary recursive( - Supplier> base, - Function, Arbitrary> recur, + public abstract Arbitrary recursive( + Supplier> base, + Function, ? extends Arbitrary> recur, int minDepth, int maxDepth ); - public abstract Arbitrary lazyOf(List>> suppliers); + public abstract Arbitrary lazyOf(List>> suppliers); public abstract TraverseArbitrary traverse(Class targetType, Traverser traverser); public abstract Arbitrary of(char[] chars); - public abstract Arbitrary of(Collection values); + public abstract Arbitrary of(Collection values); - public abstract Arbitrary create(Supplier supplier); + public abstract Arbitrary create(Supplier supplier); - public abstract Arbitrary> shuffle(List values); + public abstract Arbitrary> shuffle(List values); - public abstract Arbitrary fromGenerator(IntFunction> generatorSupplier); + public abstract Arbitrary fromGenerator(IntFunction> generatorSupplier); - public abstract Arbitrary frequency(List> frequencies); + public abstract Arbitrary frequency(List> frequencies); } private Arbitraries() { @@ -99,7 +99,7 @@ private Arbitraries() { * @param The type of values to generate * @return a new arbitrary instance */ - public static Arbitrary fromGenerator(RandomGenerator generator) { + public static Arbitrary fromGenerator(RandomGenerator generator) { return fromGeneratorWithSize(ignore -> generator); } @@ -111,7 +111,7 @@ public static Arbitrary fromGenerator(RandomGenerator generator) { * @return a new arbitrary instance */ @API(status = EXPERIMENTAL, since = "1.8.0") - public static Arbitrary fromGeneratorWithSize(IntFunction> generatorSupplier) { + public static Arbitrary fromGeneratorWithSize(IntFunction> generatorSupplier) { return ArbitrariesFacade.implementation.fromGenerator(generatorSupplier); } @@ -123,7 +123,7 @@ public static Arbitrary fromGeneratorWithSize(IntFunction The type of values to generate * @return a new arbitrary instance */ - public static Arbitrary randomValue(Function generator) { + public static Arbitrary randomValue(Function generator) { IntFunction> generatorSupplier = ignore -> random -> Shrinkable.unshrinkable(generator.apply(random)); return fromGeneratorWithSize(generatorSupplier); } @@ -153,7 +153,7 @@ public static Arbitrary randoms() { * @return a new arbitrary instance */ @SafeVarargs - public static Arbitrary of(T... values) { + public static Arbitrary of(T... values) { return of(Arrays.asList(values)); } @@ -172,7 +172,7 @@ public static Arbitrary of(T... values) { * @return a new arbitrary instance */ @API(status = MAINTAINED, since = "1.3.1") - public static <@Nullable T> Arbitrary of(Collection values) { + public static Arbitrary of(Collection values) { return ArbitrariesFacade.implementation.of(values); } @@ -192,7 +192,7 @@ public static Arbitrary of(T... values) { */ @API(status = MAINTAINED, since = "1.3.0") @SafeVarargs - public static Arbitrary ofSuppliers(Supplier... valueSuppliers) { + public static Arbitrary ofSuppliers(Supplier... valueSuppliers) { return of(valueSuppliers).map(Supplier::get); } @@ -211,7 +211,7 @@ public static Arbitrary ofSuppliers(Supplier... valueSuppliers) { * @return a new arbitrary instance */ @API(status = MAINTAINED, since = "1.3.1") - public static Arbitrary ofSuppliers(Collection> valueSuppliers) { + public static Arbitrary ofSuppliers(Collection> valueSuppliers) { return of(valueSuppliers).map(Supplier::get); } @@ -247,7 +247,7 @@ public static > Arbitrary of(Class enumClass) { */ @SuppressWarnings("unchecked") @SafeVarargs - public static Arbitrary oneOf(Arbitrary first, Arbitrary... rest) { + public static Arbitrary oneOf(Arbitrary first, Arbitrary... rest) { List> all = new ArrayList<>(); all.add(first); for (Arbitrary arbitrary : rest) { @@ -264,7 +264,7 @@ public static Arbitrary oneOf(Arbitrary first, Arbitrary Arbitrary oneOf(Collection> choices) { + public static Arbitrary oneOf(Collection> choices) { if (choices.isEmpty()) { String message = "oneOf() must not be called with no choices"; throw new JqwikException(message); @@ -285,7 +285,7 @@ public static Arbitrary oneOf(Collection> choices) * @return a new arbitrary instance */ @SafeVarargs - public static Arbitrary frequency(Tuple2... frequencies) { + public static Arbitrary frequency(Tuple2... frequencies) { return frequency(Arrays.asList(frequencies)); } @@ -297,7 +297,7 @@ public static Arbitrary frequency(Tuple2... frequencies) { * @param The type of values to generate * @return a new arbitrary instance */ - public static <@Nullable T> Arbitrary frequency(List> frequencies) { + public static Arbitrary frequency(List> frequencies) { return ArbitrariesFacade.implementation.frequency(frequencies); } @@ -311,7 +311,7 @@ public static Arbitrary frequency(Tuple2... frequencies) { */ @SuppressWarnings("unchecked") @SafeVarargs - public static Arbitrary frequencyOf(Tuple2>... frequencies) { + public static Arbitrary frequencyOf(Tuple2>... frequencies) { List>> all = new ArrayList<>(); for (Tuple2> frequency : frequencies) { all.add(Tuple.of(frequency.get1(), (Arbitrary) frequency.get2())); @@ -327,7 +327,7 @@ public static Arbitrary frequencyOf(Tuple2 The type of values to generate * @return a new arbitrary instance */ - public static <@Nullable T> Arbitrary frequencyOf(List>> frequencies) { + public static Arbitrary frequencyOf(List>> frequencies) { // Simple flatMapping is not enough because of configurations return ArbitrariesFacade.implementation.frequencyOf(frequencies); } @@ -454,7 +454,7 @@ public static CharacterArbitrary chars() { * @return a new arbitrary instance */ @API(status = MAINTAINED, since = "1.1.1") - public static Arbitrary create(Supplier supplier) { + public static Arbitrary create(Supplier supplier) { return ArbitrariesFacade.implementation.create(supplier); } @@ -468,7 +468,7 @@ public static Arbitrary create(Supplier supplier) { * @return a new arbitrary instance */ @SafeVarargs - public static Arbitrary> shuffle(T... values) { + public static Arbitrary> shuffle(T... values) { return shuffle(Arrays.asList(values)); } @@ -481,7 +481,7 @@ public static Arbitrary> shuffle(T... values) { * @param The type of values to generate * @return a new arbitrary instance */ - public static Arbitrary> shuffle(List values) { + public static Arbitrary> shuffle(List values) { return ArbitrariesFacade.implementation.shuffle(values); } @@ -591,7 +591,7 @@ public static TraverseArbitrary traverse(Class targetType, Traverser t * @see #recursive(Supplier, Function, int) * @see #lazyOf(Supplier, Supplier[]) */ - public static Arbitrary lazy(Supplier> arbitrarySupplier) { + public static Arbitrary lazy(Supplier> arbitrarySupplier) { return ArbitrariesFacade.implementation.lazy(arbitrarySupplier); } @@ -609,9 +609,9 @@ public static Arbitrary lazy(Supplier> arbitrarySupplier) { * @return a new arbitrary instance * @see #lazy(Supplier) */ - public static Arbitrary recursive( - Supplier> base, - Function, Arbitrary> recur, + public static Arbitrary recursive( + Supplier> base, + Function, ? extends Arbitrary> recur, int depth ) { return ArbitrariesFacade.implementation.recursive(base, recur, depth, depth); @@ -633,9 +633,9 @@ public static Arbitrary recursive( * @see #lazy(Supplier) */ @API(status = MAINTAINED, since = "1.6.4") - public static Arbitrary recursive( - Supplier> base, - Function, Arbitrary> recur, + public static Arbitrary recursive( + Supplier> base, + Function, ? extends Arbitrary> recur, int minDepth, int maxDepth ) { @@ -671,7 +671,7 @@ public static Arbitrary recursive( @SuppressWarnings("unchecked") @SafeVarargs @API(status = MAINTAINED, since = "1.3.4") - public static Arbitrary lazyOf(Supplier> first, Supplier>... rest) { + public static Arbitrary lazyOf(Supplier> first, Supplier>... rest) { List>> all = new ArrayList<>(); all.add(() -> (Arbitrary) first.get()); for (Supplier> arbitrarySupplier : rest) { diff --git a/api/src/main/java/net/jqwik/api/Arbitrary.java b/api/src/main/java/net/jqwik/api/Arbitrary.java index f76f8c7b4..9f0c5ed08 100644 --- a/api/src/main/java/net/jqwik/api/Arbitrary.java +++ b/api/src/main/java/net/jqwik/api/Arbitrary.java @@ -6,7 +6,7 @@ import com.google.errorprone.annotations.*; import org.apiguardian.api.*; -import org.jspecify.annotations.Nullable; +import org.jspecify.annotations.*; import net.jqwik.api.arbitraries.*; @@ -20,7 +20,7 @@ */ @API(status = STABLE, since = "1.0") @CheckReturnValue -public interface Arbitrary<@Nullable T> { +public interface Arbitrary { @API(status = INTERNAL) abstract class ArbitraryFacade { diff --git a/api/src/main/java/net/jqwik/api/Builders.java b/api/src/main/java/net/jqwik/api/Builders.java index 3a7e317d4..b96949449 100644 --- a/api/src/main/java/net/jqwik/api/Builders.java +++ b/api/src/main/java/net/jqwik/api/Builders.java @@ -53,7 +53,7 @@ private BuilderCombinator(Supplier starter, List * @return new {@linkplain CombinableBuilder} instance */ - public <@Nullable T> CombinableBuilder use(Arbitrary arbitrary) { + public CombinableBuilder use(Arbitrary arbitrary) { return new CombinableBuilder<>(this, 1.0, arbitrary); } @@ -167,7 +167,7 @@ BuilderCombinator withMutator(double probabilityOfUse, Arbitrary arbi * * @param The builder's type */ - public static class CombinableBuilder { + public static class CombinableBuilder { private final BuilderCombinator combinator; private final double probabilityOfUse; private final Arbitrary arbitrary; @@ -201,7 +201,7 @@ public CombinableBuilder withProbability(double probabilityOfUse) { * @return new {@linkplain BuilderCombinator} instance */ @SuppressWarnings("unchecked") - public BuilderCombinator in(BiFunction toFunction) { + public BuilderCombinator in(BiFunction toFunction) { if (probabilityOfUse == 0.0) { return combinator; } @@ -217,7 +217,7 @@ public BuilderCombinator in(BiFunction toFunction) { * @param setter Use value provided by arbitrary to change a builder's property. * @return new {@linkplain BuilderCombinator} instance with same embedded builder */ - public BuilderCombinator inSetter(BiConsumer setter) { + public BuilderCombinator inSetter(BiConsumer setter) { BiFunction toFunction = (b, t) -> { setter.accept(b, t); return b; diff --git a/api/src/main/java/net/jqwik/api/Combinators.java b/api/src/main/java/net/jqwik/api/Combinators.java index da7011726..a8a21dfdc 100644 --- a/api/src/main/java/net/jqwik/api/Combinators.java +++ b/api/src/main/java/net/jqwik/api/Combinators.java @@ -68,7 +68,7 @@ public abstract Combinator8 a8 ); - public abstract ListCombinator combineList(List> listOfArbitraries); + public abstract ListCombinator combineList(List> listOfArbitraries); } private Combinators() { @@ -79,7 +79,7 @@ private Combinators() { * * @return Combinator2 instance which can be evaluated using {@linkplain Combinator2#as} */ - public static <@Nullable T1, @Nullable T2> Combinator2 combine(Arbitrary a1, Arbitrary a2) { + public static Combinator2 combine(Arbitrary a1, Arbitrary a2) { return CombinatorsFacade.implementation.combine2(a1, a2); } @@ -88,7 +88,7 @@ private Combinators() { * * @return Combinator3 instance which can be evaluated using {@linkplain Combinator3#as} */ - public static <@Nullable T1, @Nullable T2, @Nullable T3> Combinator3 combine(Arbitrary a1, Arbitrary a2, Arbitrary a3) { + public static Combinator3 combine(Arbitrary a1, Arbitrary a2, Arbitrary a3) { return CombinatorsFacade.implementation.combine3(a1, a2, a3); } @@ -97,7 +97,7 @@ private Combinators() { * * @return Combinator4 instance which can be evaluated using {@linkplain Combinator4#as} */ - public static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4> Combinator4 combine( + public static Combinator4 combine( Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4 ) { @@ -109,7 +109,7 @@ private Combinators() { * * @return Combinator5 instance which can be evaluated using {@linkplain Combinator5#as} */ - public static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5> Combinator5 combine( + public static Combinator5 combine( Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5 ) { @@ -121,7 +121,7 @@ private Combinators() { * * @return Combinator6 instance which can be evaluated using {@linkplain Combinator6#as} */ - public static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6> Combinator6 combine( + public static Combinator6 combine( Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6 ) { @@ -133,7 +133,7 @@ private Combinators() { * * @return Combinator7 instance which can be evaluated using {@linkplain Combinator7#as} */ - public static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7> Combinator7 combine( + public static Combinator7 combine( Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7 ) { @@ -145,7 +145,7 @@ private Combinators() { * * @return Combinator8 instance which can be evaluated using {@linkplain Combinator8#as} */ - public static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7, @Nullable T8> Combinator8 combine( + public static Combinator8 combine( Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7, Arbitrary a8 ) { @@ -157,14 +157,14 @@ private Combinators() { * * @return ListCombinator instance which can be evaluated using {@linkplain ListCombinator#as} */ - public static <@Nullable T> ListCombinator combine(List> listOfArbitraries) { + public static ListCombinator combine(List> listOfArbitraries) { return CombinatorsFacade.implementation.combineList(listOfArbitraries); } /** * Combinator for two values. */ - public interface Combinator2<@Nullable T1, @Nullable T2> { + public interface Combinator2 { /** * Combine two values. @@ -173,7 +173,7 @@ public interface Combinator2<@Nullable T1, @Nullable T2> { * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F2 combinator); + Arbitrary as(F2 combinator); /** * Filter two values to only let them pass if the predicate is true. @@ -191,7 +191,7 @@ public interface Combinator2<@Nullable T1, @Nullable T2> { * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F2> flatCombinator) { + default Arbitrary flatAs(F2> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } } @@ -199,7 +199,7 @@ public interface Combinator2<@Nullable T1, @Nullable T2> { /** * Combinator for three values. */ - public interface Combinator3<@Nullable T1, @Nullable T2, @Nullable T3> { + public interface Combinator3 { /** * Combine three values. @@ -208,7 +208,7 @@ public interface Combinator3<@Nullable T1, @Nullable T2, @Nullable T3> { * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F3 combinator); + Arbitrary as(F3 combinator); /** * Filter three values to only let them pass if the predicate is true. @@ -226,7 +226,7 @@ public interface Combinator3<@Nullable T1, @Nullable T2, @Nullable T3> { * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F3> flatCombinator) { + default Arbitrary flatAs(F3> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } @@ -235,7 +235,7 @@ public interface Combinator3<@Nullable T1, @Nullable T2, @Nullable T3> { /** * Combinator for four values. */ - public interface Combinator4<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4> { + public interface Combinator4 { /** * Combine four values. @@ -244,7 +244,7 @@ public interface Combinator4<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F4 combinator); + Arbitrary as(F4 combinator); /** * Filter four values to only let them pass if the predicate is true. @@ -262,7 +262,7 @@ public interface Combinator4<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F4> flatCombinator) { + default Arbitrary flatAs(F4> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } @@ -271,7 +271,7 @@ public interface Combinator4<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable /** * Combinator for five values. */ - public interface Combinator5<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5> { + public interface Combinator5 { /** * Combine five values. @@ -280,7 +280,7 @@ public interface Combinator5<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F5 combinator); + Arbitrary as(F5 combinator); /** * Filter five values to only let them pass if the predicate is true. @@ -298,7 +298,7 @@ public interface Combinator5<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F5> flatCombinator) { + default Arbitrary flatAs(F5> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } } @@ -306,7 +306,7 @@ public interface Combinator5<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable /** * Combinator for six values. */ - public interface Combinator6<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6> { + public interface Combinator6 { /** * Combine six values. @@ -315,7 +315,7 @@ public interface Combinator6<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F6 combinator); + Arbitrary as(F6 combinator); /** * Filter six values to only let them pass if the predicate is true. @@ -333,7 +333,7 @@ public interface Combinator6<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F6> flatCombinator) { + default Arbitrary flatAs(F6> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } @@ -342,7 +342,7 @@ public interface Combinator6<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable /** * Combinator for seven values. */ - public interface Combinator7<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7> { + public interface Combinator7 { /** * Combine seven values. @@ -351,7 +351,7 @@ public interface Combinator7<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F7 combinator); + Arbitrary as(F7 combinator); /** * Filter seven values to only let them pass if the predicate is true. @@ -369,7 +369,7 @@ public interface Combinator7<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F7> flatCombinator) { + default Arbitrary flatAs(F7> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } @@ -378,7 +378,7 @@ public interface Combinator7<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable /** * Combinator for eight values. */ - public interface Combinator8<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7, @Nullable T8> { + public interface Combinator8 { /** * Combine eight values. @@ -387,7 +387,7 @@ public interface Combinator8<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F8 combinator); + Arbitrary as(F8 combinator); /** * Filter eight values to only let them pass if the predicate is true. @@ -405,7 +405,7 @@ public interface Combinator8<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F8> flatCombinator) { + default Arbitrary flatAs(F8> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } } @@ -422,7 +422,7 @@ public interface ListCombinator<@Nullable T> { * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(Function, R> combinator); + Arbitrary as(Function, R> combinator); /** * Filter list of values to only let them pass if the predicate is true. @@ -440,50 +440,50 @@ public interface ListCombinator<@Nullable T> { * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(Function, Arbitrary> flatCombinator) { + default Arbitrary flatAs(Function, Arbitrary> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } } @FunctionalInterface @API(status = INTERNAL) - public interface F2<@Nullable T1, @Nullable T2, @Nullable R> { + public interface F2 { R apply(T1 t1, T2 t2); } @FunctionalInterface @API(status = INTERNAL) - public interface F3<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable R> { + public interface F3 { R apply(T1 t1, T2 t2, T3 t3); } @FunctionalInterface @API(status = INTERNAL) - public interface F4<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable R> { + public interface F4 { R apply(T1 t1, T2 t2, T3 t3, T4 t4); } @FunctionalInterface @API(status = INTERNAL) - public interface F5<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable R> { + public interface F5 { R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5); } @FunctionalInterface @API(status = INTERNAL) - public interface F6<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable R> { + public interface F6 { R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6); } @FunctionalInterface @API(status = INTERNAL) - public interface F7<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7, @Nullable R> { + public interface F7 { R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7); } @FunctionalInterface @API(status = INTERNAL) - public interface F8<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7, @Nullable T8, @Nullable R> { + public interface F8 { R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8); } diff --git a/api/src/main/java/net/jqwik/api/RandomGenerator.java b/api/src/main/java/net/jqwik/api/RandomGenerator.java index 694d66742..b47f3871e 100644 --- a/api/src/main/java/net/jqwik/api/RandomGenerator.java +++ b/api/src/main/java/net/jqwik/api/RandomGenerator.java @@ -5,11 +5,12 @@ import java.util.stream.*; import org.apiguardian.api.*; +import org.jspecify.annotations.*; import static org.apiguardian.api.API.Status.*; @API(status = STABLE, since = "1.0") -public interface RandomGenerator { +public interface RandomGenerator { @API(status = INTERNAL) abstract class RandomGeneratorFacade { diff --git a/api/src/main/java/net/jqwik/api/Shrinkable.java b/api/src/main/java/net/jqwik/api/Shrinkable.java index c99d9bd3c..c7a4c87db 100644 --- a/api/src/main/java/net/jqwik/api/Shrinkable.java +++ b/api/src/main/java/net/jqwik/api/Shrinkable.java @@ -10,7 +10,7 @@ import static org.apiguardian.api.API.Status.*; @API(status = STABLE, since = "1.0") -public interface Shrinkable extends Comparable> { +public interface Shrinkable extends Comparable> { @API(status = INTERNAL) abstract class ShrinkableFacade { diff --git a/api/src/main/java/net/jqwik/api/Tuple.java b/api/src/main/java/net/jqwik/api/Tuple.java index 438d36e99..6b97d3cc1 100644 --- a/api/src/main/java/net/jqwik/api/Tuple.java +++ b/api/src/main/java/net/jqwik/api/Tuple.java @@ -37,23 +37,23 @@ static Tuple0 empty() { return Tuple.of(); } - static <@Nullable T1> Tuple1 of(T1 v1) { + static Tuple1 of(T1 v1) { return new Tuple1<>(v1); } - static <@Nullable T1, @Nullable T2> Tuple2 of(T1 v1, T2 v2) { + static Tuple2 of(T1 v1, T2 v2) { return new Tuple2<>(v1, v2); } - static <@Nullable T1, @Nullable T2, @Nullable T3> Tuple3 of(T1 v1, T2 v2, T3 v3) { + static Tuple3 of(T1 v1, T2 v2, T3 v3) { return new Tuple3<>(v1, v2, v3); } - static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4> Tuple4 of(T1 v1, T2 v2, T3 v3, T4 v4) { + static Tuple4 of(T1 v1, T2 v2, T3 v3, T4 v4) { return new Tuple4<>(v1, v2, v3, v4); } - static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5> Tuple5 of( + static Tuple5 of( T1 v1, T2 v2, T3 v3, @@ -63,7 +63,7 @@ static Tuple0 empty() { return new Tuple5<>(v1, v2, v3, v4, v5); } - static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6> Tuple6 of( + static Tuple6 of( T1 v1, T2 v2, T3 v3, @@ -74,7 +74,7 @@ static Tuple0 empty() { return new Tuple6<>(v1, v2, v3, v4, v5, v6); } - static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7> Tuple7 of( + static Tuple7 of( T1 v1, T2 v2, T3 v3, @@ -86,7 +86,7 @@ static Tuple0 empty() { return new Tuple7<>(v1, v2, v3, v4, v5, v6, v7); } - static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7, @Nullable T8> Tuple8 of( + static Tuple8 of( T1 v1, T2 v2, T3 v3, @@ -122,10 +122,10 @@ public String toString() { } } - class Tuple1<@Nullable T1> extends Tuple0 { + class Tuple1 extends Tuple0 { final T1 v1; - private Tuple1(@Nullable T1 v1) { + private Tuple1(T1 v1) { super(); this.v1 = v1; } @@ -163,7 +163,7 @@ public String toString() { } } - class Tuple2<@Nullable T1, @Nullable T2> extends Tuple1 { + class Tuple2 extends Tuple1 { final T2 v2; private Tuple2(T1 v1, T2 v2) { @@ -200,7 +200,7 @@ public int hashCode() { } } - class Tuple3<@Nullable T1, @Nullable T2, @Nullable T3> extends Tuple2 { + class Tuple3 extends Tuple2 { final T3 v3; private Tuple3(T1 v1, T2 v2, T3 v3) { @@ -238,7 +238,7 @@ public int hashCode() { } } - class Tuple4<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4> extends Tuple3 { + class Tuple4 extends Tuple3 { final T4 v4; private Tuple4(T1 v1, T2 v2, T3 v3, T4 v4) { @@ -277,7 +277,7 @@ public int hashCode() { } } - class Tuple5<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5> extends Tuple4 { + class Tuple5 extends Tuple4 { final T5 v5; private Tuple5(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5) { @@ -317,7 +317,7 @@ public int hashCode() { } } - class Tuple6<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6> extends Tuple5 { + class Tuple6 extends Tuple5 { final T6 v6; private Tuple6(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6) { @@ -358,7 +358,7 @@ public int hashCode() { } } - class Tuple7<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7> extends Tuple6 { + class Tuple7 extends Tuple6 { final T7 v7; private Tuple7( @@ -408,7 +408,7 @@ public int hashCode() { } } - class Tuple8<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7, @Nullable T8> extends Tuple7 { + class Tuple8 extends Tuple7 { final T8 v8; private Tuple8( diff --git a/api/src/main/java/net/jqwik/api/arbitraries/ArrayArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/ArrayArbitrary.java index 7a93878bf..cee278c1b 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/ArrayArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/ArrayArbitrary.java @@ -12,9 +12,11 @@ /** * Fluent interface to add functionality to arbitraries that generate instances * of Arrays + * + * @param type of the resulting array class */ @API(status = MAINTAINED, since = "1.4.0") -public interface ArrayArbitrary<@Nullable T, A> extends StreamableArbitrary { +public interface ArrayArbitrary extends StreamableArbitrary { /** * Fix the size to {@code size}. @@ -76,6 +78,6 @@ default ArrayArbitrary ofSize(int size) { * @return new arbitrary instance */ @API(status = MAINTAINED, since = "1.4.0") - ArrayArbitrary uniqueElements(Function by); + ArrayArbitrary uniqueElements(Function by); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/FunctionArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/FunctionArbitrary.java index 85bec6760..808963692 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/FunctionArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/FunctionArbitrary.java @@ -17,7 +17,7 @@ * @param The return type of the functional interface */ @API(status = MAINTAINED, since = "1.3.0") -public interface FunctionArbitrary extends Arbitrary { +public interface FunctionArbitrary extends Arbitrary { /** * @@ -28,6 +28,6 @@ public interface FunctionArbitrary extends Arbitrary { * @param answer A function that produces a concrete answer or throws an exception * @return A new instance of function arbitrary */ - FunctionArbitrary when(Predicate> parameterCondition, Function, R> answer); + FunctionArbitrary when(Predicate> parameterCondition, Function, ? extends R> answer); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/IteratorArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/IteratorArbitrary.java index d854a02b4..0d6d8e16c 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/IteratorArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/IteratorArbitrary.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -14,7 +16,7 @@ * of type {@linkplain Iterator} */ @API(status = MAINTAINED, since = "1.3.2") -public interface IteratorArbitrary extends Arbitrary>, StreamableArbitrary> { +public interface IteratorArbitrary extends Arbitrary>, StreamableArbitrary> { /** * Fix the size to {@code size}. @@ -76,6 +78,6 @@ default IteratorArbitrary ofSize(int size) { * @return new arbitrary instance */ @API(status = MAINTAINED, since = "1.4.0") - IteratorArbitrary uniqueElements(Function by); + IteratorArbitrary uniqueElements(Function by); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/ListArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/ListArbitrary.java index ed7ae6a8e..4c2e69655 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/ListArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/ListArbitrary.java @@ -16,7 +16,7 @@ * of type {@linkplain List} */ @API(status = MAINTAINED, since = "1.3.2") -public interface ListArbitrary extends Arbitrary>, StreamableArbitrary> { +public interface ListArbitrary extends Arbitrary>, StreamableArbitrary> { /** * Fix the size to {@code size}. @@ -72,7 +72,7 @@ default ListArbitrary ofSize(int size) { * @return arbitrary of a list of Us */ @API(status = MAINTAINED, since = "1.4.0") - Arbitrary> flatMapEach(BiFunction, T, Arbitrary> flatMapper); + Arbitrary> flatMapEach(BiFunction, ? super T, ? extends Arbitrary> flatMapper); /** * Add the constraint that elements of the generated list must be unique, @@ -100,5 +100,5 @@ default ListArbitrary ofSize(int size) { * @return new arbitrary instance */ @API(status = MAINTAINED, since = "1.4.0") - ListArbitrary<@Nullable T> uniqueElements(Function<@Nullable T, Object> by); + ListArbitrary uniqueElements(Function by); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/MapArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/MapArbitrary.java index fb0ec32c4..1f9ef22dc 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/MapArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/MapArbitrary.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -14,7 +16,7 @@ * of type {@linkplain Map} */ @API(status = MAINTAINED, since = "1.3.2") -public interface MapArbitrary extends Arbitrary>, SizableArbitrary> { +public interface MapArbitrary extends Arbitrary>, SizableArbitrary> { /** * Fix the size to {@code size}. diff --git a/api/src/main/java/net/jqwik/api/arbitraries/SetArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/SetArbitrary.java index d8a66e983..f9a9fe1b5 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/SetArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/SetArbitrary.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -14,7 +16,7 @@ * of type {@linkplain Set} */ @API(status = MAINTAINED, since = "1.3.2") -public interface SetArbitrary extends Arbitrary>, StreamableArbitrary> { +public interface SetArbitrary extends Arbitrary>, StreamableArbitrary> { /** * Fix the size to {@code size}. @@ -94,6 +96,6 @@ default SetArbitrary ofSize(int size) { * @return new arbitrary instance */ @API(status = MAINTAINED, since = "1.4.0") - SetArbitrary uniqueElements(Function by); + SetArbitrary uniqueElements(Function by); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/SizableArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/SizableArbitrary.java index 0035cab95..8f270a035 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/SizableArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/SizableArbitrary.java @@ -4,13 +4,15 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** * Fluent interface to configure arbitraries that have size constraints for generated values, e.g. collections and arrays. */ @API(status = MAINTAINED, since = "1.0") -public interface SizableArbitrary extends Arbitrary { +public interface SizableArbitrary extends Arbitrary { /** * Fix the size to {@code size}. diff --git a/api/src/main/java/net/jqwik/api/arbitraries/StreamArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/StreamArbitrary.java index 1c5d93d3c..c200f6b37 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/StreamArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/StreamArbitrary.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -14,7 +16,7 @@ * of type {@linkplain Stream} */ @API(status = MAINTAINED, since = "1.3.2") -public interface StreamArbitrary extends Arbitrary>, StreamableArbitrary> { +public interface StreamArbitrary extends Arbitrary>, StreamableArbitrary> { /** * Fix the size to {@code size}. @@ -76,6 +78,6 @@ default StreamArbitrary ofSize(int size) { * @return new arbitrary instance */ @API(status = MAINTAINED, since = "1.4.0") - StreamArbitrary uniqueElements(Function by); + StreamArbitrary uniqueElements(Function by); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/StreamableArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/StreamableArbitrary.java index 4f8c70f52..d45d63565 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/StreamableArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/StreamableArbitrary.java @@ -17,7 +17,7 @@ * can be streamed, e.g. {@link List}, {@link Set}, {@link Stream} and Arrays */ @API(status = MAINTAINED, since = "1.2.1") -public interface StreamableArbitrary extends SizableArbitrary { +public interface StreamableArbitrary extends SizableArbitrary { /** * Given an {@code initial} argument use {@code accumulator} to produce @@ -79,6 +79,6 @@ default StreamableArbitrary ofSize(int size) { * @return new arbitrary instance */ @API(status = MAINTAINED, since = "1.7.3") - StreamableArbitrary<@Nullable T, U> uniqueElements(Function<@Nullable T, Object> by); + StreamableArbitrary uniqueElements(Function by); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/TraverseArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/TraverseArbitrary.java index adc5cfe64..5a7ec3c20 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/TraverseArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/TraverseArbitrary.java @@ -8,6 +8,8 @@ import net.jqwik.api.*; import net.jqwik.api.providers.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -15,7 +17,7 @@ * of a given type {@code T} from the type's available constructors and factory methods. */ @API(status = MAINTAINED, since = "1.8.0") -public interface TraverseArbitrary extends Arbitrary { +public interface TraverseArbitrary extends Arbitrary { /** * A traverser describes how to travers a given type by providing a hook to diff --git a/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java index d5101fc32..0ea63796a 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -24,7 +26,7 @@ * @see net.jqwik.api.domains.DomainContext */ @API(status = MAINTAINED, since = "1.2") -public interface TypeArbitrary extends Arbitrary { +public interface TypeArbitrary extends Arbitrary { /** * Add public constructors of class {@code T} to be used diff --git a/api/src/main/java/net/jqwik/api/statistics/StatisticsCoverage.java b/api/src/main/java/net/jqwik/api/statistics/StatisticsCoverage.java index e841d5978..03856d196 100644 --- a/api/src/main/java/net/jqwik/api/statistics/StatisticsCoverage.java +++ b/api/src/main/java/net/jqwik/api/statistics/StatisticsCoverage.java @@ -80,7 +80,7 @@ interface CoverageChecker { * @param query A {@link Predicate} that takes the collected values as parameter * and returns true if the specific values shall be counted. */ - CoverageChecker checkQuery(Predicate> query); + CoverageChecker checkQuery(Predicate> query); /** * Match collected values against a regular expression. diff --git a/documentation/src/docs/include/customized-parameter-generation.md b/documentation/src/docs/include/customized-parameter-generation.md index 4970f3270..264bf2a8c 100644 --- a/documentation/src/docs/include/customized-parameter-generation.md +++ b/documentation/src/docs/include/customized-parameter-generation.md @@ -1051,14 +1051,14 @@ either [annotating parameters with `@UniqueElements`](#unique-elements) or by using one of the many `uniqueness(..)` configuration methods for collections and collection-like types: -- `ListArbitrary.uniqueElements(Function)` +- `ListArbitrary.uniqueElements(Function)` - `ListArbitrary.uniqueElements()` -- `SetArbitrary.uniqueElements(Function)` -- `StreamArbitrary.uniqueElements(Function)` +- `SetArbitrary.uniqueElements(Function)` +- `StreamArbitrary.uniqueElements(Function)` - `StreamArbitrary.uniqueElements()` -- `IteratorArbitrary.uniqueElements(Function)` +- `IteratorArbitrary.uniqueElements(Function)` - `IteratorArbitrary.uniqueElements()` -- `ArrayArbitrary.uniqueElements(Function)` +- `ArrayArbitrary.uniqueElements(Function)` - `ArrayArbitrary.uniqueElements()` - `MapArbitrary.uniqueKeys(Function)` - `MapArbitrary.uniqueValues(Function)` diff --git a/documentation/src/test/java/net/jqwik/docs/statistics/StatisticsCoverageExamples.java b/documentation/src/test/java/net/jqwik/docs/statistics/StatisticsCoverageExamples.java index 36762d99d..298371e65 100644 --- a/documentation/src/test/java/net/jqwik/docs/statistics/StatisticsCoverageExamples.java +++ b/documentation/src/test/java/net/jqwik/docs/statistics/StatisticsCoverageExamples.java @@ -57,7 +57,10 @@ void queryStatistics(@ForAll int anInt) { Statistics.collect(anInt); Statistics.coverage(coverage -> { - Predicate> isZero = params -> params.get(0) == 0; + // Note: coverage.checkQuery is untuped as it requires Predicate that must support **any** object + // So we can't have Predicate> here as checkQuery would not be able to call our + // predicate with Object values. + Predicate> isZero = params -> (Integer) params.get(0) == 0; coverage.checkQuery(isZero).percentage(p -> p > 5.0); }); } diff --git a/engine/src/main/java/net/jqwik/engine/facades/ArbitrariesFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/ArbitrariesFacadeImpl.java index 00eab6625..f4a318285 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/ArbitrariesFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/ArbitrariesFacadeImpl.java @@ -16,6 +16,8 @@ import net.jqwik.engine.properties.arbitraries.randomized.*; import net.jqwik.engine.properties.stateful.*; +import org.jspecify.annotations.*; + import static net.jqwik.engine.properties.arbitraries.ArbitrariesSupport.*; /** @@ -24,12 +26,12 @@ public class ArbitrariesFacadeImpl extends Arbitraries.ArbitrariesFacade { @Override - public Arbitrary just(T value) { + public Arbitrary just(T value) { return new JustArbitrary<>(value); } @Override - public Arbitrary oneOf(Collection> choices) { + public Arbitrary oneOf(Collection> choices) { return new OneOfArbitrary<>(choices); } @@ -39,8 +41,8 @@ public ActionSequenceArbitrary sequences(Arbitrary> a } @Override - public Arbitrary frequencyOf(List>> frequencies) { - List>> aboveZeroFrequencies = + public Arbitrary frequencyOf(List>> frequencies) { + List>> aboveZeroFrequencies = frequencies.stream().filter(f -> f.get1() > 0).collect(Collectors.toList()); if (aboveZeroFrequencies.size() == 1) { @@ -105,12 +107,12 @@ public CharacterArbitrary chars() { } @Override - public Arbitrary lazy(Supplier> arbitrarySupplier) { + public Arbitrary lazy(Supplier> arbitrarySupplier) { return new LazyArbitrary<>(arbitrarySupplier); } @Override - public Arbitrary lazyOf(List>> suppliers) { + public Arbitrary lazyOf(List>> suppliers) { int hashIdentifier = calculateIdentifier(suppliers.size()); return LazyOfArbitrary.of(hashIdentifier, suppliers); } @@ -142,12 +144,12 @@ public Arbitrary> shuffle(List values) { } @Override - public Arbitrary fromGenerator(IntFunction> generatorSupplier) { + public Arbitrary fromGenerator(IntFunction> generatorSupplier) { return new FromGeneratorWithSizeArbitrary<>(generatorSupplier); } @Override - public Arbitrary frequency(List> frequencies) { + public Arbitrary frequency(List> frequencies) { List> frequenciesAbove0 = frequencies.stream() .filter(f -> f.get1() > 0) .collect(Collectors.toList()); @@ -259,9 +261,9 @@ private static Set> createDefaultArbitraries( } @Override - public Arbitrary recursive( - Supplier> base, - Function, Arbitrary> recur, + public Arbitrary recursive( + Supplier> base, + Function, ? extends Arbitrary> recur, int minDepth, int maxDepth ) { @@ -285,8 +287,8 @@ public Arbitrary recursive( } private Arbitrary recursive( - Supplier> base, - Function, Arbitrary> recur, + Supplier> base, + Function, ? extends Arbitrary> recur, int depth ) { return new RecursiveArbitrary<>(base, recur, depth); diff --git a/engine/src/main/java/net/jqwik/engine/facades/CombinatorsFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/CombinatorsFacadeImpl.java index d11d16de1..27b8dfaa0 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/CombinatorsFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/CombinatorsFacadeImpl.java @@ -81,7 +81,7 @@ public Combinators.Combinator8 Combinators.ListCombinator combineList(List> listOfArbitraries) { + public Combinators.ListCombinator combineList(List> listOfArbitraries) { return new DefaultListCombinator<>(listOfArbitraries); } diff --git a/engine/src/main/java/net/jqwik/engine/hooks/statistics/StatisticsCollectorImpl.java b/engine/src/main/java/net/jqwik/engine/hooks/statistics/StatisticsCollectorImpl.java index 95b5725b6..cee4275a6 100644 --- a/engine/src/main/java/net/jqwik/engine/hooks/statistics/StatisticsCollectorImpl.java +++ b/engine/src/main/java/net/jqwik/engine/hooks/statistics/StatisticsCollectorImpl.java @@ -80,7 +80,7 @@ private StatisticsEntry statisticsEntry(Object[] values) { .orElse(StatisticsEntryImpl.nullFor(key)); } - private StatisticsEntry query(Predicate> query, int countAll) { + private StatisticsEntry query(Predicate> query, int countAll) { return statisticsEntries() .stream() .filter(entry -> { @@ -198,9 +198,9 @@ public CoverageChecker check(Object... values) { @SuppressWarnings("unchecked") @Override - public CoverageChecker checkQuery(Predicate> query) { + public CoverageChecker checkQuery(Predicate> query) { int countAll = countAllCollects(); - StatisticsEntry entry = query((Predicate>) query, countAll); + StatisticsEntry entry = query(query, countAll); return new CoverageCheckerImpl(label, entry, countAll); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultArrayArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultArrayArbitrary.java index 0f6e55912..4b7fadece 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultArrayArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultArrayArbitrary.java @@ -95,7 +95,7 @@ public ArrayArbitrary uniqueElements() { } @Override - public ArrayArbitrary uniqueElements(Function by) { + public ArrayArbitrary uniqueElements(Function by) { FeatureExtractor featureExtractor = by::apply; return (ArrayArbitrary) super.uniqueElements(featureExtractor); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultFunctionArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultFunctionArbitrary.java index a275971e0..e21459f08 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultFunctionArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultFunctionArbitrary.java @@ -13,7 +13,7 @@ public class DefaultFunctionArbitrary extends TypedCloneable implements Fu private final Class functionalType; private final Arbitrary resultArbitrary; - private final List>, Function, R>>> conditions = new ArrayList<>(); + private final List>, Function, ? extends R>>> conditions = new ArrayList<>(); public DefaultFunctionArbitrary(Class functionalType, Arbitrary resultArbitrary) { this.functionalType = functionalType; @@ -52,15 +52,15 @@ public boolean equals(Object o) { } private boolean conditionsAreEqual( - List>, Function, R>>> left, - List>, Function, R>>> right + List>, Function, ? extends R>>> left, + List>, Function, ? extends R>>> right ) { if (left.size() != right.size()) { return false; } for (int i = 0; i < left.size(); i++) { - Tuple2>, Function, R>> leftCondition = left.get(i); - Tuple2>, Function, R>> rightCondition = right.get(i); + Tuple2>, Function, ? extends R>> leftCondition = left.get(i); + Tuple2>, Function, ? extends R>> rightCondition = right.get(i); if (!LambdaSupport.areEqual(leftCondition.get1(), rightCondition.get1())) { return false; } @@ -94,14 +94,14 @@ private ConstantFunctionGenerator createConstantFunctionGenerator(final in } @Override - public FunctionArbitrary when(Predicate> parameterCondition, Function, R> answer) { + public FunctionArbitrary when(Predicate> parameterCondition, Function, ? extends R> answer) { DefaultFunctionArbitrary clone = typedClone(); clone.conditions.addAll(this.conditions); clone.addCondition(Tuple.of(parameterCondition, answer)); return clone; } - private void addCondition(Tuple2>, Function, R>> condition) { + private void addCondition(Tuple2>, Function, ? extends R>> condition) { conditions.add(condition); } } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultIteratorArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultIteratorArbitrary.java index ffef597f4..cd14bc789 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultIteratorArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultIteratorArbitrary.java @@ -60,7 +60,7 @@ public IteratorArbitrary withSizeDistribution(RandomDistribution distribution } @Override - public IteratorArbitrary uniqueElements(Function by) { + public IteratorArbitrary uniqueElements(Function by) { FeatureExtractor featureExtractor = by::apply; return (IteratorArbitrary) super.uniqueElements(featureExtractor); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultListArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultListArbitrary.java index 0691b3587..389031013 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultListArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultListArbitrary.java @@ -12,7 +12,7 @@ import org.jspecify.annotations.*; -public class DefaultListArbitrary extends MultivalueArbitraryBase> implements ListArbitrary { +public class DefaultListArbitrary extends MultivalueArbitraryBase> implements ListArbitrary { public DefaultListArbitrary(Arbitrary elementArbitrary) { super(elementArbitrary); @@ -68,9 +68,9 @@ public Arbitrary> mapEach(BiFunction, T, U> mapper) { // TODO: Remove duplication with DefaultSetArbitrary.flatMapEach() @Override - public Arbitrary> flatMapEach(BiFunction, T, Arbitrary> flatMapper) { + public Arbitrary> flatMapEach(BiFunction, ? super T, ? extends Arbitrary> flatMapper) { return this.flatMap(elements -> { - List> arbitraries = + List> arbitraries = elements.stream() .map(e -> flatMapper.apply(elements, e)) .collect(Collectors.toList()); @@ -79,7 +79,7 @@ public Arbitrary> flatMapEach(BiFunction, T, Arbitrary> f } @Override - public ListArbitrary<@Nullable T> uniqueElements(Function<@Nullable T, Object> by) { + public ListArbitrary uniqueElements(Function by) { FeatureExtractor featureExtractor = by::apply; return (ListArbitrary) super.uniqueElements(featureExtractor); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java index ad48dd029..5ede6e77f 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java @@ -93,7 +93,7 @@ public SetArbitrary uniqueElements() { } @Override - public SetArbitrary uniqueElements(Function by) { + public SetArbitrary uniqueElements(Function by) { FeatureExtractor featureExtractor = by::apply; return (SetArbitrary) super.uniqueElements(featureExtractor); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultStreamArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultStreamArbitrary.java index fa289d647..c706cdb5a 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultStreamArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultStreamArbitrary.java @@ -62,7 +62,7 @@ public StreamArbitrary withSizeDistribution(RandomDistribution distribution) } @Override - public StreamArbitrary uniqueElements(Function by) { + public StreamArbitrary uniqueElements(Function by) { FeatureExtractor featureExtractor = by::apply; return (StreamArbitrary) super.uniqueElements(featureExtractor); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/EdgeCasesSupport.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/EdgeCasesSupport.java index 2bb22e671..1f0ad50c9 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/EdgeCasesSupport.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/EdgeCasesSupport.java @@ -52,7 +52,7 @@ public static EdgeCases choose(final List values, int maxEdgeCases) { return EdgeCasesSupport.fromShrinkables(shrinkables); } - public static EdgeCases concatFrom(final List> arbitraries, int maxEdgeCases) { + public static EdgeCases concatFrom(final List> arbitraries, int maxEdgeCases) { List>> shrinkables = new ArrayList<>(); for (Arbitrary arbitrary : arbitraries) { shrinkables.add(new ChooseValueShrinkable<>(arbitrary, arbitraries)); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyOfArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyOfArbitrary.java index 4c884eca7..2fb69bcc5 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyOfArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyOfArbitrary.java @@ -13,10 +13,10 @@ public class FrequencyOfArbitrary implements Arbitrary, SelfConfiguringArbitrary { - private final List>> frequencies; + private final List>> frequencies; private final boolean isGeneratorMemoizable; - public FrequencyOfArbitrary(List>> frequencies) { + public FrequencyOfArbitrary(List>> frequencies) { this.frequencies = frequencies; this.isGeneratorMemoizable = frequencies.stream().allMatch(t -> t.get2().isGeneratorMemoizable()); if (this.frequencies.isEmpty()) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FromGeneratorWithSizeArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FromGeneratorWithSizeArbitrary.java index 9497e236d..38971e03b 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FromGeneratorWithSizeArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FromGeneratorWithSizeArbitrary.java @@ -7,9 +7,9 @@ public class FromGeneratorWithSizeArbitrary implements Arbitrary { - private final IntFunction> supplier; + private final IntFunction> supplier; - public FromGeneratorWithSizeArbitrary(IntFunction> generatorSupplier) { + public FromGeneratorWithSizeArbitrary(IntFunction> generatorSupplier) { this.supplier = generatorSupplier; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyArbitrary.java index 49dd53c5a..9da910f76 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyArbitrary.java @@ -8,11 +8,11 @@ import net.jqwik.api.providers.*; public class LazyArbitrary implements Arbitrary, SelfConfiguringArbitrary { - private final Supplier> arbitrarySupplier; + private final Supplier> arbitrarySupplier; private final List> configurations = new ArrayList<>(); private Arbitrary arbitrary; - public LazyArbitrary(Supplier> arbitrarySupplier) { + public LazyArbitrary(Supplier> arbitrarySupplier) { this.arbitrarySupplier = arbitrarySupplier; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java index 4cd3798f1..9afd129f8 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java @@ -24,13 +24,13 @@ private static Store>> arbitrariesStore() { } @SuppressWarnings("unchecked") - public static Arbitrary of(int hashIdentifier, List>> suppliers) { + public static Arbitrary of(int hashIdentifier, List>> suppliers) { // It's important for good shrinking to work that the same arbitrary usage is handled by the same arbitrary instance LazyOfArbitrary arbitrary = arbitrariesStore().get().computeIfAbsent(hashIdentifier, ignore -> new LazyOfArbitrary<>(suppliers)); return (Arbitrary) arbitrary; } - private final List>> suppliers; + private final List>> suppliers; private final Deque>> generatedParts = new ArrayDeque<>(); @@ -45,7 +45,7 @@ private Store>> createGeneratorsStore() { } } - public LazyOfArbitrary(List>> suppliers) { + public LazyOfArbitrary(List>> suppliers) { this.suppliers = suppliers; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/OneOfArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/OneOfArbitrary.java index 8c3eacb7b..a928246f6 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/OneOfArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/OneOfArbitrary.java @@ -16,8 +16,9 @@ public class OneOfArbitrary implements Arbitrary, SelfConfiguringArbitrary private final boolean isGeneratorMemoizable; @SuppressWarnings("unchecked") - public OneOfArbitrary(Collection> choices) { + public OneOfArbitrary(Collection> choices) { for (Arbitrary choice : choices) { + // TODO: double-check cast all.add((Arbitrary) choice); } isGeneratorMemoizable = all.stream().allMatch(Arbitrary::isGeneratorMemoizable); @@ -39,7 +40,7 @@ public boolean isGeneratorMemoizable() { } private RandomGenerator rawGeneration(int genSize, boolean withEmbeddedEdgeCases) { - List>> frequencies = + List>> frequencies = all.stream() .map(a -> Tuple.of(1, a)) .collect(Collectors.toList()); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/RecursiveArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/RecursiveArbitrary.java index c713a968b..1494c3b00 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/RecursiveArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/RecursiveArbitrary.java @@ -7,8 +7,8 @@ import net.jqwik.api.support.*; public class RecursiveArbitrary implements Arbitrary { - private final Supplier> base; - private final Function, Arbitrary> recur; + private final Supplier> base; + private final Function, ? extends Arbitrary> recur; private final int depth; // Not used for exhaustive generation @@ -16,7 +16,7 @@ public class RecursiveArbitrary implements Arbitrary { private boolean isGeneratorMemoizable = true; - public RecursiveArbitrary(Supplier> base, Function, Arbitrary> recur, int depth) { + public RecursiveArbitrary(Supplier> base, Function, ? extends Arbitrary> recur, int depth) { this.base = base; this.recur = recur; this.depth = depth; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java index 8d4c84f5d..5c661c4f7 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java @@ -15,7 +15,7 @@ public class DefaultListCombinator implements Combinators.ListCombinator { protected final Arbitrary[] arbitraries; @SuppressWarnings("unchecked") - public DefaultListCombinator(List> listOfArbitraries) { + public DefaultListCombinator(List> listOfArbitraries) { this(listOfArbitraries.toArray(new Arbitrary[0])); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java index e5281d736..2c8b50ca7 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java @@ -97,7 +97,7 @@ public static Optional>> shuffle(List values, public static Optional> flatMap( ExhaustiveGenerator base, - Function> mapper, + Function> mapper, long maxNumberOfSamples ) { Optional optionalMaxCount = FlatMappedExhaustiveGenerator.calculateMaxCounts(base, mapper, maxNumberOfSamples); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FlatMappedExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FlatMappedExhaustiveGenerator.java index 8241a4ada..3db50eaa9 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FlatMappedExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FlatMappedExhaustiveGenerator.java @@ -10,11 +10,11 @@ public class FlatMappedExhaustiveGenerator implements ExhaustiveGenerator { private final ExhaustiveGenerator baseGenerator; private final long maxCount; - private final Function> mapper; + private final Function> mapper; public static Optional calculateMaxCounts( ExhaustiveGenerator baseGenerator, - Function> mapper, + Function> mapper, long maxNumberOfSamples ) { long choices = 0; @@ -31,7 +31,7 @@ public static Optional calculateMaxCounts( return Optional.of(choices); } - public FlatMappedExhaustiveGenerator(ExhaustiveGenerator baseGenerator, long maxCount, Function> mapper) { + public FlatMappedExhaustiveGenerator(ExhaustiveGenerator baseGenerator, long maxCount, Function> mapper) { this.baseGenerator = baseGenerator; this.maxCount = maxCount; this.mapper = mapper; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/AbstractFunctionGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/AbstractFunctionGenerator.java index 67fcb862d..9edab461f 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/AbstractFunctionGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/AbstractFunctionGenerator.java @@ -13,12 +13,12 @@ abstract class AbstractFunctionGenerator implements RandomGenerator { final Class functionalType; final RandomGenerator resultGenerator; - final List>, Function, R>>> conditions; + final List>, Function, ? extends R>>> conditions; AbstractFunctionGenerator( Class functionalType, RandomGenerator resultGenerator, - List>, Function, R>>> conditions + List>, Function, ? extends R>>> conditions ) { this.functionalType = functionalType; this.resultGenerator = resultGenerator; @@ -70,7 +70,7 @@ private Object handleToStringOfConstantMethod(final R constant) { // Returns result wrapped in array to allow null as result protected Optional conditionalResult(Object[] args) { Optional conditionalResult = Optional.empty(); - for (Tuple2>, Function, R>> condition : conditions) { + for (Tuple2>, Function, ? extends R>> condition : conditions) { List params = Arrays.asList(args); if (condition.get1().test(params)) { Object[] result = new Object[]{condition.get2().apply(params)}; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ConstantFunctionGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ConstantFunctionGenerator.java index 31743d2b8..4343f8304 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ConstantFunctionGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ConstantFunctionGenerator.java @@ -11,7 +11,7 @@ public class ConstantFunctionGenerator extends AbstractFunctionGenerator functionalType, RandomGenerator resultGenerator, - List>, Function, R>>> conditions + List>, Function, ? extends R>>> conditions ) { super(functionalType, resultGenerator, conditions); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FrequencyGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FrequencyGenerator.java index 6f0ccd185..cedb08da0 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FrequencyGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FrequencyGenerator.java @@ -8,7 +8,7 @@ class FrequencyGenerator extends ChooseRandomlyByFrequency implements RandomGenerator { - FrequencyGenerator(List> frequencies) { + FrequencyGenerator(List> frequencies) { super(frequencies); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FunctionGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FunctionGenerator.java index f1750e2f5..12022209d 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FunctionGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FunctionGenerator.java @@ -18,7 +18,7 @@ public class FunctionGenerator extends AbstractFunctionGenerator { public FunctionGenerator( Class functionalType, RandomGenerator resultGenerator, - List>, Function, R>>> conditions + List>, Function, ? extends R>>> conditions ) { super(functionalType, resultGenerator, conditions); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/RandomGenerators.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/RandomGenerators.java index cf1a30fd2..5e6fb3a1e 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/RandomGenerators.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/RandomGenerators.java @@ -174,12 +174,12 @@ public static RandomGenerator samples(T[] samples) { return samplesFromShrinkables(shrinkables); } - public static RandomGenerator frequency(List> frequencies) { + public static RandomGenerator frequency(List> frequencies) { return new FrequencyGenerator<>(frequencies); } public static RandomGenerator frequencyOf( - List>> frequencies, + List>> frequencies, int genSize, boolean withEmbeddedEdgeCases ) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ChooseValueShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ChooseValueShrinkable.java index 96ee7c9ca..c3bf061a7 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ChooseValueShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ChooseValueShrinkable.java @@ -7,9 +7,9 @@ public class ChooseValueShrinkable extends AbstractValueShrinkable { - private final List values; + private final List values; - public ChooseValueShrinkable(T value, List values) { + public ChooseValueShrinkable(T value, List values) { super(value); this.values = values; } diff --git a/engine/src/main/java/net/jqwik/engine/support/ChooseRandomlyByFrequency.java b/engine/src/main/java/net/jqwik/engine/support/ChooseRandomlyByFrequency.java index 891abaf78..1b1faf86e 100644 --- a/engine/src/main/java/net/jqwik/engine/support/ChooseRandomlyByFrequency.java +++ b/engine/src/main/java/net/jqwik/engine/support/ChooseRandomlyByFrequency.java @@ -11,7 +11,7 @@ public class ChooseRandomlyByFrequency implements Function { private int size = 0; private List valuesToChooseFrom; - public ChooseRandomlyByFrequency(List> frequencies) { + public ChooseRandomlyByFrequency(List> frequencies) { calculateUpperBorders(frequencies); if (size <= 0) { throw new JqwikException(String.format( @@ -25,11 +25,11 @@ protected List possibleValues() { return valuesToChooseFrom; } - private void calculateUpperBorders(List> frequencies) { + private void calculateUpperBorders(List> frequencies) { List values = new ArrayList<>(frequencies.size()); // Zero-frequency elements are possible, so we start with a list, and transform to array later List upperBounds = new ArrayList<>(frequencies.size()); - for (Tuple.Tuple2 tuple : frequencies) { + for (Tuple.Tuple2 tuple : frequencies) { int frequency = tuple.get1(); if (frequency <= 0) continue; diff --git a/engine/src/test/java/net/jqwik/api/statistics/StatisticsCoverageTests.java b/engine/src/test/java/net/jqwik/api/statistics/StatisticsCoverageTests.java index fede04bb1..1e5cf24f7 100644 --- a/engine/src/test/java/net/jqwik/api/statistics/StatisticsCoverageTests.java +++ b/engine/src/test/java/net/jqwik/api/statistics/StatisticsCoverageTests.java @@ -240,7 +240,7 @@ void checkCountForQuery(@ForAll @IntRange(min = 1, max = 100) int anInt) { Statistics.collect(anInt); Statistics.coverage(coverage -> { - Predicate> query = params -> params.get(0) <= 10; + Predicate> query = params -> (Integer) params.get(0) <= 10; coverage.checkQuery(query).count(c -> c == 10); }); } @@ -250,7 +250,7 @@ void checkPercentageForQuery(@ForAll @IntRange(min = 1, max = 100) int anInt) { Statistics.collect(anInt); Statistics.coverage(coverage -> { - Predicate> query = params -> params.get(0) <= 50; + Predicate> query = params -> (Integer) params.get(0) <= 50; coverage.checkQuery(query).percentage(p -> { assertThat(p).isCloseTo(50.0, Offset.offset(0.1)); }); @@ -263,7 +263,7 @@ void checkCountsAreAddedUp(@ForAll @IntRange(min = 1, max = 100) int anInt) { Statistics.label("twice").collect(anInt); Statistics.label("twice").coverage(coverage -> { - Predicate> query = params -> params.get(0) <= 10; + Predicate> query = params -> (Integer) params.get(0) <= 10; coverage.checkQuery(query).count(c -> c == 20); }); } @@ -274,7 +274,7 @@ void queryWithWrongTypeFails(@ForAll int anInt) { Statistics.collect(anInt); Statistics.coverage(coverage -> { - Predicate> query = params -> !params.get(0).isEmpty(); + Predicate> query = params -> !((String)params.get(0)).isEmpty(); coverage.checkQuery(query).count(c -> c == 10); }); } diff --git a/kotlin/build.gradle b/kotlin/build.gradle index 311c9d46a..1b849e9f8 100644 --- a/kotlin/build.gradle +++ b/kotlin/build.gradle @@ -78,6 +78,7 @@ signing { tasks.withType(KotlinCompile).configureEach { compilerOptions { freeCompilerArgs = [ + "-Xnullability-annotations=@org.jspecify.annotations:strict", "-Xemit-jvm-type-annotations" // Required for annotations on type variables ] apiVersion = KotlinVersion.KOTLIN_1_9 diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt index a25baa473..b8a2771a8 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt @@ -9,10 +9,8 @@ import java.util.function.BiFunction * Convenience function for Kotlin to not use backticked `in` function. */ @API(status = API.Status.EXPERIMENTAL, since = "1.6.0") -fun BuilderCombinator.use(arbitrary: Arbitrary, combinator: (B, T) -> B): BuilderCombinator +fun BuilderCombinator.use(arbitrary: Arbitrary, combinator: (B, T) -> B): BuilderCombinator where B : Any { - // This explicit conversion form combinator to toFunction is necessary - // since the implicit conversion (just handing in combinator) creates nullability warning - val toFunction: BiFunction = BiFunction { b, t -> combinator(b, t) } + val toFunction = BiFunction { b, t -> combinator(b, t) } return this.use(arbitrary).`in`(toFunction) } diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SequenceArbitrary.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SequenceArbitrary.kt index 9a0b023e5..1b75d2170 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SequenceArbitrary.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SequenceArbitrary.kt @@ -15,7 +15,7 @@ import java.util.function.Function * of type [Sequence] */ @API(status = EXPERIMENTAL, since = "1.6.0") -class SequenceArbitrary(elementArbitrary: Arbitrary) : ArbitraryDecorator>(), +class SequenceArbitrary(elementArbitrary: Arbitrary) : ArbitraryDecorator>(), SizableArbitrary> { private var listArbitrary: ListArbitrary @@ -80,7 +80,7 @@ class SequenceArbitrary(elementArbitrary: Arbitrary) : ArbitraryDecorator< * * @return new arbitrary instance */ - fun uniqueElements(by: Function): SequenceArbitrary { + fun uniqueElements(by: Function): SequenceArbitrary { val clone = typedClone>() clone.listArbitrary = listArbitrary.uniqueElements(by) return clone diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SizableArbitraryExtensions.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SizableArbitraryExtensions.kt index 67d802fd9..0b9ddd1c9 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SizableArbitraryExtensions.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SizableArbitraryExtensions.kt @@ -19,4 +19,4 @@ fun IteratorArbitrary.ofSize(range: IntRange): IteratorArbitrary = ofM fun MapArbitrary.ofSize(range: IntRange): MapArbitrary = ofMinSize(range.first).ofMaxSize(range.last) @API(status = API.Status.EXPERIMENTAL, since = "1.6.0") -fun ArrayArbitrary.ofSize(range: IntRange): ArrayArbitrary = ofMinSize(range.first).ofMaxSize(range.last) +fun ArrayArbitrary.ofSize(range: IntRange): ArrayArbitrary = ofMinSize(range.first).ofMaxSize(range.last) diff --git a/kotlin/src/test/kotlin/net/jqwik/kotlin/CollectionExtensionsTests.kt b/kotlin/src/test/kotlin/net/jqwik/kotlin/CollectionExtensionsTests.kt index 531372020..b0115584b 100644 --- a/kotlin/src/test/kotlin/net/jqwik/kotlin/CollectionExtensionsTests.kt +++ b/kotlin/src/test/kotlin/net/jqwik/kotlin/CollectionExtensionsTests.kt @@ -1,7 +1,7 @@ package net.jqwik.kotlin -import net.jqwik.api.Example -import net.jqwik.api.ForAll +import net.jqwik.api.* +import net.jqwik.kotlin.api.any import net.jqwik.kotlin.api.anySubset import net.jqwik.kotlin.api.anyValue import net.jqwik.kotlin.api.ofSize diff --git a/kotlin/src/test/kotlin/net/jqwik/kotlin/InternalModifierTests.kt b/kotlin/src/test/kotlin/net/jqwik/kotlin/InternalModifierTests.kt index 62d84be0b..bed36587d 100644 --- a/kotlin/src/test/kotlin/net/jqwik/kotlin/InternalModifierTests.kt +++ b/kotlin/src/test/kotlin/net/jqwik/kotlin/InternalModifierTests.kt @@ -1,12 +1,10 @@ package net.jqwik.kotlin -import net.jqwik.api.ForAll -import net.jqwik.api.Property -import net.jqwik.api.PropertyDefaults -import net.jqwik.api.Provide +import net.jqwik.api.* import net.jqwik.api.lifecycle.AfterContainer import net.jqwik.api.lifecycle.AfterProperty import net.jqwik.kotlin.api.any +import kotlin.random.Random @PropertyDefaults(tries = 10) internal class InternalModifierTests {