Skip to content

Kotlin interoperability #52

@tmohme

Description

@tmohme

Testing Problem

In Kotlin we want to express something like this:

@Property
fun myTest(@ForAll bigDecimals : List<BigDecimal>) {...}

which is (almost) the equivalent to the following Java code:

@Property
void myTest(@ForAll List<BigDecimal> bigDecimals) {...}

What looks easy and works out of the box with Java produces a net.jqwik.api.CannotFindArbitraryException: Cannot find an Arbitrary for Parameter of type [@net.jqwik.api.ForAll(value=) List<? extends BigDecimal>] with Kotlin.
The difference is obviously the type signature which for Java is List<BigDecimal> while it is List<? extends BigDecimal> for Kotlin.
Due to this little difference, the BigDecimalArbitraryProvider decides that he is unable to provide values for the given targetType.

Suggested Solution

The BigDecimalArbitraryProvider could use the more forgivingtargetType.isAssignableFrom(BigDecimal.class) instead of the stricter targetType.isOfType(BigDecimal.class) to determine if he is able to provide the requested values.
The same applies to some of the other *ArbitraryProviders.
Interestingly, currently not all *ArbitraryProviders are structured the same.
While the providers for BigDecimal and BigInteger use isOfType(...) others (like Boolean, Integer, ...) use isAssignableFrom(...).

Discussion

We tried to get around this by creating our own provider for BigDecimals, but experienced problems in the aftermath when we had trouble to let our provider correctly work with jqwik constraint annotations (like @bigrange). Probably we are missing some knowledge here . . .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions