-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
DefaultArgumentConverter
no longer converts "null"
to false
#3472
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
Comments
This is now the expected behavior due to #3177. However, we may consider a way to switch back to lenient parsing of boolean values or make the true/false values somehow configurable. |
DefaultArgumentConverter
no longer treats "null"
as false
DefaultArgumentConverter
no longer treats "null"
as false
StringToBooleanConverter
no longer treats "null"
as false
@sbrannen I'm not sure this title change accurately reflects the behavior change. In the past |
My initial tests do not reveal that, but perhaps I am missing something. Previously, we used
If I'm not mistaken, we previously converted Based on that, this is technically a regression, but I don't yet know if we will "fix" this regression. In any case, I'll introduce more extensive testing around this. |
StringToBooleanConverter
no longer treats "null"
as false
DefaultArgumentConverter
no longer treats "null"
as false
Were you perhaps using the @ParameterizedTest
@CsvSource(nullValues = "null", value = ...)
void myTest(...) {
} If not, I don't see how |
DefaultArgumentConverter
no longer treats "null"
as false
DefaultArgumentConverter
no longer treats null
as false
In summary, the following test passes against @ParameterizedTest
@CsvSource(nullValues = "null", textBlock = """
apple, True
banana, true
lemon, false
kumquat, null
""")
void yummyFruit(String fruit, Boolean yummy) {
switch (fruit) {
case "apple" -> assertThat(yummy).isTrue();
case "banana" -> assertThat(yummy).isTrue();
case "lemon" -> assertThat(yummy).isFalse();
case "kumquat" -> assertThat(yummy).isNull();
default -> fail("Unexpected fruit : " + fruit);
}
} Whereas, the following test fails against @ParameterizedTest
@CsvSource(textBlock = """
apple, True
banana, true
lemon, false
kumquat, null
""")
void yummyFruit(String fruit, Boolean yummy) {
switch (fruit) {
case "apple" -> assertThat(yummy).isTrue();
case "banana" -> assertThat(yummy).isTrue();
case "lemon" -> assertThat(yummy).isFalse();
case "kumquat" -> assertThat(yummy).isNull();
default -> fail("Unexpected fruit : " + fruit);
}
} To make the above test pass, you have to change the assertion for kumquat as follows. @ParameterizedTest
@CsvSource(textBlock = """
apple, True
banana, true
lemon, false
kumquat, null
""")
void yummyFruit(String fruit, Boolean yummy) {
switch (fruit) {
case "apple" -> assertThat(yummy).isTrue();
case "banana" -> assertThat(yummy).isTrue();
case "lemon" -> assertThat(yummy).isFalse();
case "kumquat" -> assertThat(yummy).isFalse();
default -> fail("Unexpected fruit : " + fruit);
}
} The latter test passes against So the regression is that But... that makes sense, because we now only convert |
DefaultArgumentConverter
no longer treats null
as false
DefaultArgumentConverter
no longer converts "null"
to false
…ed tests 2 tests in this commit currently fail due to changes in 5.10 with the failure message: Failed to convert String "null" to type java.lang.Boolean This will be addressed in a subsequent commit to align with the expected behavior in 5.10.x. See #3472
…ed tests 2 tests in this commit currently fail due to changes in 5.10 with the failure message: Failed to convert String "null" to type java.lang.Boolean This will be addressed in a subsequent commit to align with the expected behavior in 5.10.x. See #3472
To observe the actual behavioral changes, consult the following commits.
The latter commit makes it clear that the only thing that has changed is that we now only convert |
This is very helpful. Thank you. I'll update my csv source tests with this in mind. I'll further investigate my other failing tests to see what else could be the problem. |
You're welcome.
OK. Let us know if you run into any other issues. |
All of my failures were related to |
Error message:
Failed to convert String "null" to type java.lang.Boolean
Working Version:
5.9.2
Broken Version:
5.10.0
Steps to reproduce
Use the
DefaultArgumentConverter
to convert a string to a Boolean. Strings"true"
and"false"
convert correctly, but the string"null"
no longer converts to anull
Boolean
(wrapper type) after upgrading.Since this converter is used for
@CsvSource
data in@ParameterizedTest
methods , it is quite common to include nulls in those sources for many types, not justBoolean.class
.A naive fix and test for this issue is included in my fork of junit5. I suspect a more robust fix for nullable types more broadly should be considered.
main...JKomoroski:junit5:main
Deliverables
"null"
->null
conversions once again.The text was updated successfully, but these errors were encountered: