-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Locale
argument conversion not setting language
and country
properly
#3141
Comments
I propose to change the implementation at: Line 265 in 4288cf1
replacing Happy to work on it if accepted. |
@scordio IIUC that could potentially break existing tests that (wrongly or not) rely on the |
@marcphilipp yes, but only if they specify a country and/or variant in the string. They would be broken like the second test case you currently have in the codebase. However, such tests would have today a "wrong" Tests that are specifying only a "plain" language (i.e., without country, variant, etc.) are safe from my point of view, which might be the most common use case. |
Looking at Java 19, the |
In case you prefer to keep the current behavior thus avoiding a breaking change, an alternative could be an opt-in argument converter like A few ideas about naming:
The implicit conversion could then be changed in the next major version of JUnit. |
We (JUnit Pioneer) also changed our implementation as the old constructor is deprecated, see JUnit Pioneer issue and JUnit Pioneer PR. Why do I note this here? Because some of the builder methods validates the input against a valid pattern - which the old constructor did not. So you might have the same discussion as we if you see this as a breaking change or not. |
Thanks for the pointers, @Bukama! As far as I can see, JUnit Pioneer favored the builder only when the fine-grained parameters are specified, otherwise Do you see any issue with using |
I would not expect any issues as this method does not do a syntax check (as far as I understand the docs) |
As mentioned in #2702 (comment), a custom argument converter could be a candidate for JUnit Pioneer. |
Team decision: Since the |
During the team discussion (resulting in the above team decision), I mentioned that Spring Framework dealt with this issue by introducing "lenient" Locale parsing in order to support both legacy locale formats as well as BCP 47 formats.
|
Hi @marcphilipp and @sbrannen, I was going to submit a feature request to JUnit Pioneer for a custom argument converter, but stopped because I'm guessing that having the behavior configurable in JUnit would probably make the Pioneer converter obsolete. I understand you're waiting for additional interest. I am definitely interested in having a solution, one way or another, but I also understand a single person's need doesn't count as a community interest 😅 I'm happy to help with the changes, but some initial design would of course be required. In case you're open to discussing the solution further, here is my proposal: as I can hardly imagine test suites where you want to have a combination of the old and new conversion behavior for In case you don't want to invest more in this right now, that's totally fine and understood! |
@scordio Wouldn't it rather be "ISO 639" vs. "BCP 47"? |
@marcphilipp I guess you're referring to the values of the configuration property, right? If the change would be the one I mentioned at #3141 (comment), yes, "ISO 639" vs. "BCP 47" would make more sense as property values. In the previous comment, I proposed Just as a last comment, I was reading again the Javadoc of Spring's
I tested how the two solutions would perform with such use cases:
Neither of the underscore and space use cases are adequately supported by either new My proposal would be to not support them as they are not backed by any standard. Thoughts? |
@marcphilipp if you don't have objections, I'll compose a PR in the next few days for this topic. |
SGTM. Sorry for the delayed response. I was out for a few days. |
I am trying to write a parameterized test for a service that uses a resource bundle under the hood, loading the resource bundle with
ResourceBundle.getBundle(String, Locale)
.The test gets several
Locale
values in a@CsvSource
annotation:The documentation does not have an example for a country-based locale so I initially tried with:
All worked fine on Windows (local environment) but failed on Linux (CI).
After some digging, on Windows everything works because it's a case-insensitive file system, so for example the
en_FR
value is converted to aen_fr
language-only locale (i.e., without country) and it successfully matches the file ending withen_FR
because of case insensitivity.Looking at the code, I think the problem is here:
junit5/junit-jupiter-params/src/main/java/org/junit/jupiter/params/converter/DefaultArgumentConverter.java
Line 265 in 4288cf1
which uses the
Locale(String)
constructor. The constructor Javadoc also explains the different behavior based on case sensitivity:Looking at the test cases:
junit5/junit-jupiter-params/src/test/java/org/junit/jupiter/params/converter/DefaultArgumentConverterTests.java
Lines 222 to 223 in 4288cf1
Probably the second one is invalid. I would have expected that to be:
which does not pass with the current implementation.
Steps to reproduce
As the documentation does not cover conversion of locales with country, I am not sure what would be the "right" test case to demonstrate the issue.
Assuming the IETF BCP 47 language tag format would be the right format for input values, this test fails already at the first assertion:
Workaround
Currently, I'm using a custom
ArgumentConverter
which delegates the conversion toLocale::forLanguageTag
.Context
Deliverables
DefaultArgumentConverter
properly converts IETF BCP 47 stringsThe text was updated successfully, but these errors were encountered: