problem-spring-web
problem-spring-web copied to clipboard
BindAdviceTraitTest's test failure. message is not following locale(English) setting.
Description
In the BindAdviceTraitTest class, when the locale is set to English by LocaleContextHolder.setLocale(Locale.ENGLISH) in the setUp method with BeforeEach, problem.getViolations().get(*).getMessage() is output in Korean according to my locale instead of English.
Expected Behavior
problem.getViolations().get().getMessage() is "size must be between 3 and 10". problem.getViolations().get().getMessage() is "must be greater than or equal to 0".
Actual Behavior
problem.getViolations().get().getMessage() is "크기가 3에서 10 사이여야 합니다"
problem.getViolations().get().getMessage() is "0 이상이어야 합니다"
Possible Fix
Steps to Reproduce
Context
Your Environment
- Version used: 0.29.0-SNAPSHOT
- Link to your project: nothing changed yet. just test case failures
Is spring using that locale holder for bean validation?
On Fri, 14 Apr 2023, 12:50 arthur.yoon, @.***> wrote:
Description
In the BindAdviceTraitTest class, when the locale is set to English by LocaleContextHolder.setLocale(Locale.ENGLISH) in the setUp method with BeforeEach, problem.getViolations().get(*).getMessage() is output in Korean according to my locale instead of English. Expected Behavior
problem.getViolations().get( ).getMessage() is "size must be between 3 and 10". problem.getViolations().get().getMessage() is "must be greater than or equal to 0". Actual Behavior
problem.getViolations().get( ).getMessage() is "크기가 3에서 10 사이여야 합니다" problem.getViolations().get().getMessage() is "0 이상이어야 합니다" [image: image] https://user-images.githubusercontent.com/47406496/232022814-82e3b277-4f5c-4e96-ab90-7a6f71e803a3.png Possible Fix Steps to Reproduce
Context Your Environment
- Version used: 0.29.0-SNAPSHOT
- Link to your project: nothing changed yet. just test case failures
— Reply to this email directly, view it on GitHub https://github.com/zalando/problem-spring-web/issues/905, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADI7HK5IW2KDTBEFLPVTS3XBETWDANCNFSM6AAAAAAW6IJZNI . You are receiving this because you are subscribed to this thread.Message ID: @.***>
I at least experience the same with my laptop being set to German, so I also get issues with the test execution.
LocaleContextHolder.setLocale(Locale.ENGLISH
it's not enough to call LocaleContextHolder.setLocale(Locale.ENGLISH), which sets the Locale information used by Spring. LocaleContextHolder.setLocale(Locale.ENGLISH) sets the locale to English for the just current thread. However, the error messages used by Bean Validation are obtained from Spring's MessageSource, which by default uses the operating system's default locale.
I at least experience the same with my laptop being set to German, so I also get issues with the test execution.
It's correct to use English as the message source instead of changing the locale setting, but I don't think this is a good idea, because if the message.properties are changed, the test case will eventually break. Shouldn't we modify it to something other than testing if the sentences match?
is this issue handled?