Skip to content
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

withData does not take Nullable types #2718

Closed
Hydragyrum opened this issue Dec 8, 2021 · 2 comments · Fixed by #2728
Closed

withData does not take Nullable types #2718

Hydragyrum opened this issue Dec 8, 2021 · 2 comments · Fixed by #2728
Labels
bug 🐛 Issues that report a problem or error in the code. data-driven-testing 🗃️ Related to the data driven testing mechanisms within the testing framework.
Milestone

Comments

@Hydragyrum
Copy link

I have a use case where I with to pass a List<String?> in the withData function. However, the function requires a non-nullable type
TypeVariable<T>

eg:

val listOfData = listOf(
  "one",
  "two",
  null
)
withData<String?>({ "Test with $it"}, listOfData) { string ->
  // Test code here
}
@Hydragyrum
Copy link
Author

A workaround is to create a holder class which takes a Nullable type, but it's somewhat awkward.

For example:

@JvmInline
value class NullableStringHolder(val value: String?) {
  override fun toString(): String {
    return "[$value]"
  }
}

and use that

val listOfData = listOf(
  NullableStringHolder("one"),
  NullableStringHolder("two"),
  NullableStringHolder(null)
)
withData<NullableStringHolder>({ "Test with $it"}, listOfData) { string ->
  // Test code here
}

This creates a lot of unnecessary boilerplate

@sksamuel
Copy link
Member

Fixed in 5.0.2

@sksamuel sksamuel added this to the 5.0.2 milestone Dec 10, 2021
@sksamuel sksamuel added bug 🐛 Issues that report a problem or error in the code. data-driven-testing 🗃️ Related to the data driven testing mechanisms within the testing framework. labels Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Issues that report a problem or error in the code. data-driven-testing 🗃️ Related to the data driven testing mechanisms within the testing framework.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants