-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate nulls for parameters annotated as Nullable #210
Conversation
@berrueta Thanks for this! I'll review and get back with you soon! |
@berrueta A couple of questions for you:
Cheers! |
Hi @pholser , Thank you for your feedback. I intentionally aimed for a minimalistic change in this first iteration so I could receive some feedback. I like your suggestion to turn Do you have any suggestion on how to expose the configurable probability I'll confirm the behaviour in the case of primitive types, and add some documentation. |
@berrueta For configuring the probability of |
Hi @pholser , I followed your suggestion and transformed I'm not done yet. I still have to make the probability Thank you. |
I've pushed a commit introducing a new
Any feedback would be welcome. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Diego, thanks for this! I have a few suggestions, spread throughout the changeset.
Once we agree on the code, please do add as many tests as you can stand, and a section in the Markdown docs indicating that you can signal to the generators how often to inject null
.
core/src/main/java/com/pholser/junit/quickcheck/internal/generator/GeneratorRepository.java
Show resolved
Hide resolved
core/src/main/java/com/pholser/junit/quickcheck/internal/generator/GeneratorRepository.java
Show resolved
Hide resolved
core/src/main/java/com/pholser/junit/quickcheck/internal/generator/NullAllows.java
Outdated
Show resolved
Hide resolved
That makes it unusable to inspect by reflection whether the parameter is nullable.
This allows to write properties that take nullable parameters. This is particularly useful in Kotlin, where explicitly nullable types are very common (they serve similar purposes to the Optional type in Java 8+).
Rather than adding support for all the annotations that can indicate nullability (for example, these are the ones that the Kotlin compiler understands: https://github.com/JetBrains/kotlin/blob/master/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.kt#L21 ), I've kept it to a minimum, but enough to have interoperability with Kotlin.
In the absence of annotations, null will not be generated, therefore this change is backwards compatible and will not break existing properties in Java or Kotlin.